import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{i as t}from"./framework-CXnKph_e.js";import{c as n,h as r}from"./index-DuOGIqz4.js";var i=e(t()),a=Symbol.for(`vinext.serverInsertedHTMLContext`);function o(){if(typeof i.createContext!=`function`)return null;let e=globalThis;return e[a]||(e[a]=i.createContext(null)),e[a]??null}o();var s=Symbol(`vinext.navigation.readonlySearchParams`),c=Symbol(`vinext.navigation.readonlySearchParamsSource`),l=Symbol.for(`vinext.navigation.globalAccessors`),u=Symbol.for(`vinext.navigation.clientHydrationContext`);function d(){return globalThis[l]}function f(){let e=globalThis;if(Object.prototype.hasOwnProperty.call(e,u))return e[u]??null}var p=null,m=()=>{if(typeof window<`u`){let e=f();return e===void 0?p:e}let e=d();return e?e.getServerContext():p},h=typeof window>`u`,g=Symbol.for(`vinext.clientNavigationState`);function _(){if(h)return null;let e=window;return e[g]??={listeners:new Set,cachedSearch:window.location.search,cachedReadonlySearchParams:new n(window.location.search),cachedPathname:r(window.location.pathname,``),clientParams:{},clientParamsJson:`{}`,pendingClientParams:null,pendingClientParamsJson:null,pendingPathname:null,pendingPathnameNavId:null,originalPushState:window.history.pushState.bind(window.history),originalReplaceState:window.history.replaceState.bind(window.history),patchInstalled:!1,hasPendingNavigationUpdate:!1,suppressUrlNotifyCount:0,navigationSnapshotActiveCount:0},e[g]}function v(){let e=_();if(e)for(let t of e.listeners)t()}var y=null,b=null;function x(){return _()?.cachedReadonlySearchParams||(b===null&&(b=new n),b)}function S(){let e=_();if(!e)return!1;let t=!1,i=r(window.location.pathname,``);i!==e.cachedPathname&&(e.cachedPathname=i,t=!0);let a=window.location.search;return a!==e.cachedSearch&&(e.cachedSearch=a,e.cachedReadonlySearchParams=new n(a),t=!0),t}function C(){let e=m();if(!e)return y===null&&(y=new n),y;let t=e.searchParams,r=e[s],i=e[c];if(r&&i===t)return r;let a=new n(t);return e[s]=a,e[c]=t,a}var w=Symbol.for(`vinext.clientNavigationRenderContext`);function T(){if(typeof i.createContext!=`function`)return null;let e=globalThis;return e[w]||(e[w]=i.createContext(null)),e[w]??null}function E(){let e=T();if(!e||typeof i.useContext!=`function`)return null;try{return i.useContext(e)}catch{return null}}function D(e){let t=_();return t?(t.listeners.add(e),()=>{t.listeners.delete(e)}):()=>{}}function O(){if(h)return C();let e=E(),t=i.useSyncExternalStore(D,x,C);return e&&(_()?.navigationSnapshotActiveCount??0)>0?e.searchParams:t}function k(e,t){if(h)return;let n=_();if(!n)return;(e!==void 0||t?.releaseSnapshot===!0)&&n.navigationSnapshotActiveCount>0&&--n.navigationSnapshotActiveCount;let r=S();n.pendingClientParams!==null&&n.pendingClientParamsJson!==null&&(n.clientParams=n.pendingClientParams,n.clientParamsJson=n.pendingClientParamsJson,n.pendingClientParams=null,n.pendingClientParamsJson=null),(n.pendingPathnameNavId===null||e!==void 0&&n.pendingPathnameNavId===e)&&(n.pendingPathname=null,n.pendingPathnameNavId=null);let i=r||n.hasPendingNavigationUpdate;n.hasPendingNavigationUpdate=!1,i&&v()}function A(e){if(e&&typeof e==`object`&&`__vinext_scrollY`in e){let{__vinext_scrollX:t,__vinext_scrollY:n}=e;Promise.resolve().then(()=>{let e=window.__VINEXT_RSC_PENDING__??null;e?e.then(()=>{requestAnimationFrame(()=>{window.scrollTo(t,n)})}):requestAnimationFrame(()=>{window.scrollTo(t,n)})})}}if(!h){let e=_();e&&!e.patchInstalled&&(e.patchInstalled=!0,window.addEventListener(`popstate`,e=>{typeof window.__VINEXT_RSC_NAVIGATE__!=`function`&&(k(),A(e.state))}),window.history.pushState=function(t,n,r){e.originalPushState.call(window.history,t,n,r),e.suppressUrlNotifyCount===0&&k()},window.history.replaceState=function(t,n,r){e.originalReplaceState.call(window.history,t,n,r),e.suppressUrlNotifyCount===0&&k()})}export{O as t};