"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gem-sdk/core"),t=require("react");exports.default=o=>{let{width:s,position:l}=o??{},{desktop:r,tablet:i,mobile:b}=o?.display||{},p=e.makeStyleResponsive("w",s),a=e.usePageStore(e=>"interaction"===e.sidebarMode),u=e.useCurrentDevice(),[d,n]=t.useState(!1),m=e.useStickyStore(e=>e.getFirstVisibleElement(u)),k=(e,t)=>({[`--left${t}`]:"top"==e?"0":"50%",[`--t${t}`]:"top"==e?"unset":"translateX(-50%)"}),c=t.useMemo(()=>({...k(l?.desktop,""),...k(l?.tablet??l?.desktop,"-tablet"),...k(l?.mobile??l?.tablet??l?.desktop,"-mobile")}),[l?.desktop,l?.mobile,l?.tablet]),f=t.useMemo(()=>{if(a&&l?.[u]==="top")return"40px"},[u,a,l]),x=t.useMemo(()=>{let e=e=>"after-first-cart-button"!==e||d?"block":"none";return{"--d":e(r),"--d-tablet":e(i??r),"--d-mobile":e(b??i??r)}},[r,i,b,d]),M=t.useMemo(()=>({"--top":f??"auto","--top-tablet":f??"auto","--top-mobile":f??"auto",[`--${l?.desktop}`]:f??"0px",[`--${l?.tablet??l?.desktop}-tablet`]:f??"0px",[`--${l?.mobile??l?.tablet??l?.desktop}-mobile`]:f??"0px"}),[f,l?.desktop,l?.mobile,l?.tablet]),v=e=>"top"==e?"sticky":"fixed",g=t.useMemo(()=>({"--pos":v(l?.desktop),"--pos-tablet":v(l?.tablet??l?.desktop),"--pos-mobile":v(l?.mobile??l?.tablet??l?.desktop)}),[l?.desktop,l?.mobile,l?.tablet]);return t.useEffect(()=>{if(!m)return;let e=new IntersectionObserver(([e])=>{e&&n(e.isIntersecting||e.boundingClientRect.top<=0)});return e.observe(m),()=>e.disconnect()},[m]),t.useEffect(()=>{n(!1)},[u]),{w:p,displayStyle:M,positionStyle:g,getCSSAlign:c,makeDisplaySettingStyles:x}};
