import{j as g}from"./jsx-runtime-C5WNSv3b.js";import{r as l}from"./index-Az39ZADK.js";import{f as y,u as w}from"./chunk-UIGDSWPH-BWkP6tD5.js";const h={vertical:"scrollTop",horizontal:"scrollLeft"};function N({elementQuery:r,direction:u="vertical",...S}){const e=`position:${r}`,f=y(),p=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,[p.key]:t[a]};sessionStorage.setItem(e,JSON.stringify(n))},[e,r,p.key]);l.useEffect(()=>{if(f.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,f.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-BwZqB-mh.js.map
