import{getContext as t,getElement as e,store as i}from"@wordpress/interactivity";const o=(t,e)=>t.getBoundingClientRect().bottom+e<=window.innerHeight?"open-bottom":"open-top",s=(t,e)=>{t.classList.remove("open-top","open-bottom"),t.classList.add(e)},{actions:n}=i("x-currency/switcher",{state:{hideWrapper:()=>t().hide},callbacks:{initSwitcher:()=>{const i=e(),n=t(),c=i.ref.querySelector(".display-none");if(c&&c.classList.remove("display-none"),i.ref.classList.contains("x-currency-shortcode")){i.ref.classList.add("open-bottom");const t=i.ref.querySelector(".currency-wrap");if(t){const e=window.getComputedStyle(t).top,c=(t=>{const e={display:t.style.display,visibility:t.style.visibility,position:t.style.position,opacity:t.style.opacity};t.style.display="block",t.style.visibility="hidden",t.style.position="absolute",t.style.opacity="0";const i=t.offsetHeight;return Object.assign(t.style,e),i})(t)+(parseFloat(e.replace("px",""))||0);n.wrapperHeight=c;const r=()=>{const t=o(i.ref,n.wrapperHeight);s(i.ref,t)},a=(t=>{let e;return function(...i){clearTimeout(e),e=setTimeout(()=>{clearTimeout(e),t(...i)},100)}})(r);r(),window.addEventListener("resize",a),window.addEventListener("scroll",a)}}}},actions:{clickSwitcher:()=>{const i=t(),n=e().ref.closest(".x-currency-shortcode"),c=!i.hide;n&&i.wrapperHeight&&(c||(()=>{const t=o(n,i.wrapperHeight);s(n,t)})()),i.hide=c},clickOption:()=>{const e=t();e.hide=!e.hide,n.clickStickyOption()},clickStickyOption:()=>{const t=e().ref.dataset.code,i=new URLSearchParams(window.location.search);i.set("currency",t);const o=i.toString(),s=`${window.location.origin}${window.location.pathname}?${o}`;window.location.href=s}}});