import{c as u,u as m,r as p,j as g}from"./index-ukWRVZhT.js";import{c as y}from"./components-BgKv_YmS.js";function h({elementQuery:n,...f}){const e=`position:${n}`,c=u(),a=m(),i=p.useCallback(()=>{const t=document.querySelector(n);if(!t)return;let s={};try{const o=JSON.parse(sessionStorage.getItem(e)||"{}");typeof o=="object"&&o!==null&&(s=o)}catch(o){console.warn("Error parsing scroll positions from sessionStorage:",o)}const r={...s,[a.key]:t.scrollTop};sessionStorage.setItem(e,JSON.stringify(r))},[e,n,a.key]);p.useEffect(()=>{if(c.state==="idle"){const t=document.querySelector(n);if(!t)return;try{const r=JSON.parse(sessionStorage.getItem(e)||"{}")[window.history.state.key];typeof r=="number"&&(t.scrollTop=r)}catch(s){console.error(s),sessionStorage.removeItem(e)}}else i()},[e,n,c.state,i]),y(()=>{i()});function S(t,s){const r=document.querySelector(s);if(!r){console.warn(`Element not found: ${s}. Cannot restore scroll.`);return}if(!window.history.state||!window.history.state.key){const o=Math.random().toString(32).slice(2);window.history.replaceState({key:o},"")}try{const l=JSON.parse(sessionStorage.getItem(t)||"{}")[window.history.state.key];typeof l=="number"&&(r.scrollTop=l)}catch(o){console.error(o),sessionStorage.removeItem(t)}}return g.jsx("script",{...f,suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:`(${S})(${JSON.stringify(e)}, ${JSON.stringify(n)})`}})}export{h as E};
//# sourceMappingURL=index-gUr5Pw56.js.map
