{"version":3,"file":"5aeab3ce.js","sources":["../../../node_modules/@shopify/hydrogen/dist/esnext/foundation/useNavigate/useNavigate.js"],"sourcesContent":["import { useRouter } from '../Router/BrowserRouter.client.js';\nimport { useBasePath } from '../useRouteParams/RouteParamsProvider.client.js';\n/**\n * The useNavigate hook imperatively navigates between routes.\n */\nexport function useNavigate() {\n const router = useRouter();\n const routeBasePath = useBasePath();\n return (path, options = { replace: false, reloadDocument: false }) => {\n path = buildPath(options.basePath ?? routeBasePath, path);\n const state = {\n ...options?.clientState,\n scroll: options?.scroll ?? true,\n };\n // @todo wait for RSC and then change focus for a11y?\n if (options?.replace) {\n router.history.replace(path, state);\n }\n else {\n router.history.push(path, state);\n }\n };\n}\nexport function buildPath(basePath, path) {\n if (path.startsWith('http') || path.startsWith('//'))\n return path;\n let builtPath = path;\n if (basePath !== '/') {\n const pathFirstChar = path.charAt(0);\n const basePathLastChar = basePath.charAt(basePath.length - 1);\n builtPath =\n pathFirstChar === '/' && basePathLastChar === '/'\n ? basePath + path.substring(1)\n : basePathLastChar !== '/' && pathFirstChar !== '/'\n ? basePath + '/' + path\n : basePath + path;\n }\n return builtPath;\n}\n"],"names":["useNavigate","router","useRouter","routeBasePath","useBasePath","path","options","buildPath","_a","state","_b","basePath","builtPath","pathFirstChar","basePathLastChar"],"mappings":"8EAKO,SAASA,GAAc,CAC1B,MAAMC,EAASC,IACTC,EAAgBC,IACtB,MAAO,CAACC,EAAMC,EAAU,CAAE,QAAS,GAAO,eAAgB,MAAY,SAClED,EAAOE,GAAUC,EAAAF,EAAQ,WAAR,KAAAE,EAAoBL,EAAeE,CAAI,EACxD,MAAMI,EAAQ,CACV,GAAGH,GAAA,YAAAA,EAAS,YACZ,QAAQI,EAAAJ,GAAA,YAAAA,EAAS,SAAT,KAAAI,EAAmB,EACvC,EAEYJ,GAAA,MAAAA,EAAS,QACTL,EAAO,QAAQ,QAAQI,EAAMI,CAAK,EAGlCR,EAAO,QAAQ,KAAKI,EAAMI,CAAK,CAE3C,CACA,CACO,SAASF,EAAUI,EAAUN,EAAM,CACtC,GAAIA,EAAK,WAAW,MAAM,GAAKA,EAAK,WAAW,IAAI,EAC/C,OAAOA,EACX,IAAIO,EAAYP,EAChB,GAAIM,IAAa,IAAK,CAClB,MAAME,EAAgBR,EAAK,OAAO,CAAC,EAC7BS,EAAmBH,EAAS,OAAOA,EAAS,OAAS,CAAC,EAC5DC,EACIC,IAAkB,KAAOC,IAAqB,IACxCH,EAAWN,EAAK,UAAU,CAAC,EAC3BS,IAAqB,KAAOD,IAAkB,IAC1CF,EAAW,IAAMN,EACjBM,EAAWN,CAC5B,CACD,OAAOO,CACX"}