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