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