{"version":3,"file":"useLocalizeHref.mjs","names":[],"sources":["../../src/link/useLocalizeHref.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useDefaultLocale, useLocale } from 'gt-react';\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 navigation that does not render a `<Link>`, such as `router.push()`.\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 * 'use client';\n *\n * import { useRouter } from 'next/navigation';\n * import { useLocalizeHref } from 'gt-next/link';\n *\n * export function Checkout() {\n *   const router = useRouter();\n *   const localizeHref = useLocalizeHref();\n *   return (\n *     <button onClick={() => router.push(localizeHref('/checkout'))}>\n *       Checkout\n *     </button>\n *   );\n * }\n * ```\n *\n * @returns A function taking an href and an optional locale (a locale string,\n * or `false` to leave the href unchanged) that returns the localized href.\n */\nexport function useLocalizeHref(): (\n  href: string,\n  locale?: LinkLocale\n) => string {\n  const currentLocale = useLocale();\n  const defaultLocale = useDefaultLocale();\n  return useCallback(\n    (href, locale) => localizeHref(href, locale, currentLocale, defaultLocale),\n    [currentLocale, defaultLocale]\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,kBAGJ;CACV,MAAM,gBAAgB,WAAW;CACjC,MAAM,gBAAgB,kBAAkB;AACxC,QAAO,aACJ,MAAM,WAAW,aAAa,MAAM,QAAQ,eAAe,cAAc,EAC1E,CAAC,eAAe,cAAc,CAC/B"}