{"version":3,"file":"Footnotes.mjs","names":["Flexbox"],"sources":["../../../src/Markdown/components/Footnotes.tsx"],"sourcesContent":["'use client';\n\nimport { memo, type ReactNode, useMemo } from 'react';\n\nimport A from '@/A';\nimport Block from '@/Block';\nimport { Flexbox } from '@/Flex';\nimport Text from '@/Text';\n\nimport SearchResultCards from './SearchResultCards';\n\ninterface FootnotesProps {\n  'children': ReactNode;\n  'data-footnote-links'?: string;\n  'data-footnotes'?: boolean;\n}\n\nconst DefaultFootnotes = memo<{ dataSource: any[] }>(({ dataSource }) => {\n  const items = useMemo(\n    () =>\n      dataSource\n        .find((child) => child?.type === 'ol')\n        ?.props?.children?.map((item: any) => {\n          if (typeof item === 'string' || item?.type !== 'li') return false;\n          const data = item?.props?.children?.find((note: any) => note?.props?.children)?.props\n            ?.children;\n          if (!data || !Array.isArray(data)) return false;\n          return {\n            children: data[0],\n            props: data[1]?.props || {},\n          };\n        })\n        .filter(Boolean),\n    [dataSource],\n  );\n\n  if (!Array.isArray(items)) return null;\n\n  return (\n    <Flexbox\n      horizontal\n      align={'flex-start'}\n      as={'section'}\n      className={'footnotes'}\n      data-footnotes=\"true\"\n      gap={'0.5em'}\n      justify={'flex-start'}\n      wrap={'wrap'}\n    >\n      {items.map(({ children, props }, index) => {\n        const { node, href, ...rest } = props;\n        const Container = href ? A : 'div';\n        return (\n          <Container {...(href ? { href, ...rest } : rest)} key={index}>\n            <Block\n              horizontal\n              align={'stretch'}\n              style={{ overflow: 'hidden', position: 'relative' }}\n              variant={'outlined'}\n            >\n              <Block paddingInline={'0.66em'} style={{ borderRadius: 0 }} variant={'filled'}>\n                <Text code as=\"span\" type={'secondary'}>\n                  {index + 1}\n                </Text>\n              </Block>\n              <Text as=\"span\" style={{ paddingInline: '0.66em' }} type={'secondary'}>\n                {children}\n              </Text>\n            </Block>\n          </Container>\n        );\n      })}\n    </Flexbox>\n  );\n});\n\nconst Footnotes = memo<FootnotesProps>(({ children, ...rest }) => {\n  const links = useMemo(() => {\n    try {\n      return JSON.parse(rest['data-footnote-links'] || '[]');\n    } catch (error) {\n      console.error('Failed to parse footnote links:', error);\n      return [];\n    }\n  }, [rest['data-footnote-links']]);\n\n  const isError = links.length === 0;\n\n  if (!children) return;\n\n  if (isError) {\n    if (!Array.isArray(children)) return children;\n    return <DefaultFootnotes dataSource={children} />;\n  }\n\n  return (\n    <section className={'footnotes'} data-footnotes=\"true\">\n      <SearchResultCards dataSource={links} />\n    </section>\n  );\n});\n\nFootnotes.displayName = 'Footnotes';\n\nexport default Footnotes;\n"],"mappings":";;;;;;;;;AAiBA,MAAM,mBAAmB,MAA6B,EAAE,iBAAiB;CACvE,MAAM,QAAQ,cAEV,WACG,MAAM,UAAU,OAAO,SAAS,IAAI,CAAC,EACpC,OAAO,UAAU,KAAK,SAAc;EACpC,IAAI,OAAO,SAAS,YAAY,MAAM,SAAS,MAAM,OAAO;EAC5D,MAAM,OAAO,MAAM,OAAO,UAAU,MAAM,SAAc,MAAM,OAAO,QAAQ,CAAC,EAAE,OAC5E;EACJ,IAAI,CAAC,QAAQ,CAAC,MAAM,QAAQ,IAAI,GAAG,OAAO;EAC1C,OAAO;GACL,UAAU,KAAK;GACf,OAAO,KAAK,EAAE,EAAE,SAAS,CAAC;EAC5B;CACF,CAAC,CAAC,CACD,OAAO,OAAO,GACnB,CAAC,UAAU,CACb;CAEA,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO;CAElC,OACE,oBAACA,mBAAD;EACE,YAAA;EACA,OAAO;EACP,IAAI;EACJ,WAAW;EACX,kBAAe;EACf,KAAK;EACL,SAAS;EACT,MAAM;YAEL,MAAM,KAAK,EAAE,UAAU,SAAS,UAAU;GACzC,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS;GAEhC,OACE,8BAFgB,OAAO,IAAI,OAE3B;IAAW,GAAK,OAAO;KAAE;KAAM,GAAG;IAAK,IAAI;IAAO,KAAK;GAgB5C,GAfT,qBAAC,OAAD;IACE,YAAA;IACA,OAAO;IACP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