{"version":3,"file":"useLocalePageRouter.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport {\n  getLocalizedUrl,\n  getPathWithoutLocale,\n} from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\nimport type { UseLocaleProps, UseLocaleResult } from './useLocale';\n\n/**\n * Hook to manage the current locale in Next.js Page Router.\n *\n * This hook provides locale management functionality tailored for the Next.js Page Router,\n * handling redirections and page reloads upon locale changes.\n *\n * @returns An object containing the current locale, path without locale, and functions to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocalePageRouter } from 'next-intlayer';\n *\n * const MyComponent = () => {\n *   const { setLocale } = useLocalePageRouter();\n *\n *   return (\n *     <button onClick={() => setLocale('fr')}>Switch to French</button>\n *   );\n * };\n * ```\n */\nexport const useLocalePageRouter = ({\n  onLocaleChange,\n  isCookieEnabled,\n}: UseLocaleProps = {}): UseLocaleResult => {\n  const { push, pathname, reload } = useRouter();\n  const pathWithoutLocale = useMemo(\n    () => getPathWithoutLocale(pathname),\n    [pathname]\n  );\n\n  const redirectionFunction = useCallback(\n    (locale: LocalesValues) => {\n      const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n      push(pathWithLocale);\n\n      onLocaleChange?.(locale as Locale);\n\n      return reload();\n    },\n    [pathWithoutLocale, onLocaleChange, reload]\n  );\n\n  const reactLocaleHook = useLocaleReact({\n    onLocaleChange: redirectionFunction,\n    isCookieEnabled,\n  });\n\n  return {\n    ...reactLocaleHook,\n    pathWithoutLocale,\n  } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,uBAAuB,EAClC,gBACA,oBACkB,CAAC,MAAuB;CAC1C,MAAM,EAAE,MAAM,UAAU,WAAW,UAAU;CAC7C,MAAM,oBAAoB,cAClB,qBAAqB,QAAQ,GACnC,CAAC,QAAQ,CACX;CAoBA,OAAO;EACL,GANsBA,UAAe;GACrC,gBAd0B,aACzB,WAA0B;IAGzB,KAFuB,gBAAgB,mBAAmB,MAExC,CAAC;IAEnB,iBAAiB,MAAgB;IAEjC,OAAO,OAAO;GAChB,GACA;IAAC;IAAmB;IAAgB;GAAM,CAIR;GAClC;EACF,CAGmB;EACjB;CACF;AACF"}