{"version":3,"file":"useRewriteURL.cjs","names":["useLocale","routing","getRewritePath"],"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,mCAAU;CAC7B,MAAM,UAAUC,gCAAS;CAEzB,2BAAgB;EACd,IAAI,OAAO,WAAW,eAAe,CAAC,SAAS;EAE/C,MAAM,WAAW,OAAO,SAAS;EACjC,MAAM,iBAAaC,4CAAe,UAAU,QAAkB,OAAO;EAErE,IAAI,cAAc,eAAe,UAC/B,OAAO,QAAQ,aACb,OAAO,QAAQ,OACf,IACA,aAAa,OAAO,SAAS,SAAS,OAAO,SAAS,IACxD;CAEJ,GAAG,CAAC,QAAQ,OAAO,CAAC;AACtB"}