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