{"version":3,"file":"getLocalizeHref.mjs","names":[],"sources":["../../src/link/getLocalizeHref.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { getLocale } from '../request/getLocale';\nimport { use } from '../utils/use';\nimport { localizeHref, type LinkLocale } from './localize-utils';\n\n/**\n * Returns a function that localizes hrefs the same way `gt-next/link` does,\n * for server code such as Server Components, route handlers, and Server\n * Actions.\n *\n * Internal paths are prefixed with the target locale, except default-locale\n * paths when `prefixDefaultLocale` is `false` (an explicit default `locale`\n * keeps its prefix while `enableSmartRouting` is on). Localized path aliases\n * and locale availability are still resolved by the middleware. External URLs\n * and paths that don't match `pathRegex` are never prefixed.\n *\n * @example\n * ```tsx\n * import { getLocalizeHref } from 'gt-next/server';\n *\n * export async function CheckoutButton() {\n *   const localizeHref = await getLocalizeHref();\n *   return <Button href={localizeHref('/checkout')}>Checkout</Button>;\n * }\n * ```\n *\n * @returns A promise of a function taking an href and an optional locale (a\n * locale string, or `false` to leave the href unchanged) that returns the\n * localized href.\n */\nexport async function getLocalizeHref(): Promise<\n  (href: string, locale?: LinkLocale) => string\n> {\n  const currentLocale = await getLocale();\n  const defaultLocale = getI18nConfig().getDefaultLocale();\n  return (href, locale) =>\n    localizeHref(href, locale, currentLocale, defaultLocale);\n}\n\n/**\n * Server Component version of `useLocalizeHref()`: localizes hrefs the same\n * way `gt-next/link` does, using the request locale.\n *\n * @example\n * ```tsx\n * import { useLocalizeHref } from 'gt-next';\n *\n * export function CheckoutButton() {\n *   const localizeHref = useLocalizeHref();\n *   return <Button href={localizeHref('/checkout')}>Checkout</Button>;\n * }\n * ```\n */\nexport function useLocalizeHref() {\n  return use(getLocalizeHref());\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,eAAsB,kBAEpB;CACA,MAAM,gBAAgB,MAAM,WAAW;CACvC,MAAM,gBAAgB,eAAe,CAAC,kBAAkB;AACxD,SAAQ,MAAM,WACZ,aAAa,MAAM,QAAQ,eAAe,cAAc;;;;;;;;;;;;;;;;AAiB5D,SAAgB,kBAAkB;AAChC,QAAO,IAAI,iBAAiB,CAAC"}