import{S as e}from"./SwatchGroup-daCWa7EX.js";class t extends React.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){}componentDidUpdate(e,t){this.state.hasError&&!t.hasError&&this.revealFallbackSelect()}revealFallbackSelect(){const{fallbackSelect:e}=this.props;if(!e)return;const t=e.closest(".b3-wvs-original-select");t&&(t.style.display="");const s=e.closest(".b3-wvs-swatches-container");s&&(s.classList.remove("b3-wvs-initialized"),s.classList.add("b3-wvs-fallback"))}render(){return this.state.hasError?null:this.props.children}}const s=(...e)=>{},a=new WeakMap,r=({forceRemount:s=!1,SwatchGroupComponent:r=e}={})=>{document.querySelectorAll(".b3-wvs-swatches-mount").forEach(e=>{var o;const n=e.closest(".b3-wvs-swatches-container");if(!n)return;if(s){null==(o=a.get(e))||o.unmount(),a.delete(e),delete e.dataset.b3WvsMounted,n.classList.remove("b3-wvs-initialized"),n.classList.add("b3-wvs-fallback");const t=n.querySelector(".b3-wvs-original-select");t&&(t.style.display="")}if(n.classList.contains("b3-wvs-initialized")||"1"===e.dataset.b3WvsMounted)return;const c=n.dataset.attribute,l=(e=>{if(!e)return{};try{return JSON.parse(e)}catch(t){return{}}})(n.dataset.swatches),i=n.querySelector("select");if(!(c&&i instanceof HTMLSelectElement))return;const d=ReactDOM.createRoot(e);a.set(e,d),d.render(React.createElement(React.StrictMode,null,React.createElement(t,{fallbackSelect:i},React.createElement(r,{attribute:c,select:i,swatches:l})))),e.dataset.b3WvsMounted="1",n.classList.add("b3-wvs-initialized"),n.classList.remove("b3-wvs-fallback");const u=n.querySelector(".b3-wvs-original-select");u&&(u.style.display="none")})};let o=!1;const n=()=>{o||(o=!0,window.setTimeout(()=>{document.querySelectorAll(".b3-wvs-swatches-container").forEach(e=>{e.classList.contains("b3-wvs-initialized")||e.classList.add("b3-wvs-fallback")})},3e3))};let c=!1;const l=new Set,i=e=>{l.add(e),c||(c=!0,requestAnimationFrame(()=>{c=!1,l.forEach(e=>e())}))},d=e=>{"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()},u=e=>{if("undefined"==typeof MutationObserver)return;const t=document.body||document.documentElement;if(!t)return;new MutationObserver(t=>{var s,a,r;for(const o of t)for(const t of Array.from(o.addedNodes))if(t instanceof HTMLElement){if(t.matches(".b3-wvs-swatches-mount")||t.querySelector(".b3-wvs-swatches-mount"))return null==(s=e.onSwatchMountAdded)||s.call(e),void(null==(a=e.onVariationFormAdded)||a.call(e));if(t.matches("form.variations_form")||t.querySelector("form.variations_form"))return void(null==(r=e.onVariationFormAdded)||r.call(e))}}).observe(t,{childList:!0,subtree:!0})};export{u as a,i as b,s as d,r as i,d as o,n as s};
