import*as e from"@wordpress/interactivity";var t,o,r={d:function(e,t){for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},n=(t={getContext:function(){return e.getContext},getElement:function(){return e.getElement},store:function(){return e.store},withScope:function(){return e.withScope}},o={},r.d(o,t),o);const{state:c}=(0,n.store)("surecart/product-list");let i=[];const u=e=>!e?.key||[" ","Enter","Escape"].includes(e.key),{state:s,actions:a}=(0,n.store)("surecart/product-quick-view",{actions:{*navigate(e){const{url:t}=(0,n.getContext)();e?.preventDefault(),s.loading=!0,c.loading=!0;const{actions:o}=yield import("@wordpress/interactivity-router");yield o.navigate(t,{replace:!0}),c.loading=!1,s.loading=!1},*prefetch(){const{url:e}=(0,n.getContext)(),{actions:t}=yield import("@wordpress/interactivity-router");yield t.prefetch(e)},*open(e){if(!u(e))return;e?.preventDefault(),s.openButton=e?.target?.closest(".wp-block-surecart-product-quick-view-button"),e&&(yield a.navigate(e)),s.open=!0;const t=document.querySelector(".wp-block-surecart-product-quick-view")?.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');t?.focus()},*close(e){if(!s.open||!u(e))return;e?.preventDefault();const{ref:t}=(0,n.getElement)(),o=t?.closest(".wp-block-surecart-product-quick-view"),r=(0,n.withScope)((e=>{o?.getAnimations()?.length>0||(a.navigate(e),o.removeEventListener("transitionend",r))}));o.addEventListener("transitionend",r),s.open=!1,setTimeout((()=>s?.openButton?.focus()),1)}},callbacks:{handleOpenChange(){i.length||(i=Array.from(document.querySelectorAll("body > :not(.sc-lightbox-overlay):not(.wp-block-surecart-product-quick-view)")).filter((e=>!e.hasAttribute("inert")&&!e.querySelector(".wp-block-surecart-product-quick-view")&&!e.querySelector(".sc-lightbox-overlay")))),s.open?(document.body.classList.add("sc-product-quick-view-open"),i.forEach((e=>e.setAttribute("inert","")))):(document.body.classList.remove("sc-product-quick-view-open"),i.forEach((e=>e.removeAttribute("inert"))))},handleKeyDown(e){"Escape"===e?.key&&a.close(e)}}});