{"version":3,"file":"Link.mjs","names":[],"sources":["../../src/link/Link.tsx"],"sourcesContent":["'use client';\n\nimport NextLink from 'next/link';\nimport { forwardRef, type ComponentProps, type ComponentRef } from 'react';\nimport { useLocalizeHref } from './useLocalizeHref';\n\ntype LinkRef = ComponentRef<typeof NextLink>;\n\nexport type LinkProps = ComponentProps<typeof NextLink>;\n\n/**\n * Locale-aware wrapper around Next.js's `<Link>` component.\n *\n * Internal hrefs are prefixed with the current GT locale by default. Pass a\n * locale string to use a specific locale, or pass `locale={false}` to leave the\n * href unchanged. External URLs and paths that don't match `pathRegex` are\n * never prefixed.\n *\n * With `prefixDefaultLocale: false` (the default), current default-locale links\n * are left unprefixed. Explicit default-locale links are left unprefixed only\n * when `enableSmartRouting` is `false`. Set these options in `withGTConfig()`\n * so Link can read them. Use `useLocalizeHref()` to localize hrefs outside Link.\n *\n * @example\n * ```tsx\n * import Link from 'gt-next/link';\n *\n * export function Navigation() {\n *   return <Link href=\"/home\">Home</Link>; // /fr/home, or /home for the default locale\n * }\n * ```\n *\n * @example\n * ```tsx\n * import Link from 'gt-next/link';\n *\n * export function LocaleSwitcher() {\n *   return <Link href=\"/home\" locale=\"fr\">French</Link>; // /fr/home\n * }\n * ```\n *\n * @example\n * ```tsx\n * import Link from 'gt-next/link';\n *\n * export function UnlocalizedLink() {\n *   return <Link href=\"/legal\" locale={false}>Legal</Link>; // /legal\n * }\n * ```\n *\n * @example\n * ```tsx\n * import Link from 'gt-next/link';\n *\n * export function ExternalLink() {\n *   return <Link href=\"https://example.com\">Example</Link>; // https://example.com\n * }\n * ```\n *\n * @see https://nextjs.org/docs/app/api-reference/components/link\n * @param href - The destination URL or URL object. Internal paths are localized.\n * @param locale - Locale to prefix, or `false` to disable GT locale prefixing.\n * @returns The rendered Next.js link.\n */\nexport const Link = forwardRef<LinkRef, LinkProps>(function Link(\n  { href, locale, ...props },\n  ref\n) {\n  const localizeHref = useLocalizeHref();\n\n  let localizedHref = href;\n  if (typeof href === 'string') {\n    localizedHref = localizeHref(href, locale);\n  } else if (typeof href.pathname === 'string') {\n    const pathname = localizeHref(href.pathname, locale);\n    if (pathname !== href.pathname) localizedHref = { ...href, pathname };\n  }\n\n  return <NextLink {...props} href={localizedHref} ref={ref} />;\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,MAAa,OAAO,WAA+B,SAAS,KAC1D,EAAE,MAAM,QAAQ,GAAG,SACnB,KACA;CACA,MAAM,eAAe,iBAAiB;CAEtC,IAAI,gBAAgB;AACpB,KAAI,OAAO,SAAS,SAClB,iBAAgB,aAAa,MAAM,OAAO;UACjC,OAAO,KAAK,aAAa,UAAU;EAC5C,MAAM,WAAW,aAAa,KAAK,UAAU,OAAO;AACpD,MAAI,aAAa,KAAK,SAAU,iBAAgB;GAAE,GAAG;GAAM;GAAU;;AAGvE,QAAO,oBAAC,UAAD;EAAU,GAAI;EAAO,MAAM;EAAoB;EAAO,CAAA;EAC7D"}