{"version":3,"file":"useRewriteURL.cjs","names":["useLocale","routing"],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["'use client';\n\nimport { routing } from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useEffect } from 'react';\nimport { useLocale } from './useLocale';\n\n/**\n * Client-side hook to manage URL rewrites without triggering a router navigation.\n * It uses `window.history.replaceState` to update the URL in the address bar.\n *\n * This hook is useful to \"prettify\" the URL when the user lands on a canonical path\n * that has a localized alias defined in `intlayer.config.ts`.\n *\n * @example\n * ```tsx\n * import { useRewriteURL } from 'react-intlayer';\n *\n * const MyComponent = () => {\n *   useRewriteURL();\n *\n *   return <div>My Component</div>;\n * };\n * ```\n */\nexport const useRewriteURL = (): void => {\n  const { locale } = useLocale();\n  const rewrite = routing?.rewrite;\n\n  useEffect(() => {\n    if (typeof window === 'undefined' || !rewrite) return;\n\n    const pathname = window.location.pathname;\n    const targetPath = getRewritePath(pathname, locale as Locale, rewrite);\n\n    if (targetPath && targetPath !== pathname) {\n      window.history.replaceState(\n        window.history.state,\n        '',\n        targetPath + window.location.search + window.location.hash\n      );\n    }\n  }, [locale, rewrite]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,sBAA4B;CACvC,MAAM,EAAE,WAAWA,oCAAW;CAC9B,MAAM,UAAUC,gCAAS;AAEzB,4BAAgB;AACd,MAAI,OAAO,WAAW,eAAe,CAAC,QAAS;EAE/C,MAAM,WAAW,OAAO,SAAS;EACjC,MAAM,6DAA4B,UAAU,QAAkB,QAAQ;AAEtE,MAAI,cAAc,eAAe,SAC/B,QAAO,QAAQ,aACb,OAAO,QAAQ,OACf,IACA,aAAa,OAAO,SAAS,SAAS,OAAO,SAAS,KACvD;IAEF,CAAC,QAAQ,QAAQ,CAAC"}