import*as e from"@wordpress/interactivity";var t={d:(e,o)=>{for(var a in o)t.o(o,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:o[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const o=(i={getContext:()=>e.getContext,getElement:()=>e.getElement,store:()=>e.store},l={},t.d(l,i),l),a=e=>(0,o.getContext)(e),n=(e,t)=>({disableLeft:1===e,disableRight:e===t}),c={state:{get isSelected(){const{selectedImageNumber:e,imageIds:t,imageId:o}=a();return e===t.indexOf(o)+1},get imageIndex(){const{imageIds:e,imageId:t}=a();return e.indexOf(t)},get thumbnailTabIndex(){return r.isSelected?"0":"-1"}},actions:{selectImage:e=>{const t=a(),{disableLeft:o,disableRight:c}=n(e,t.imageIds.length);t.selectedImageNumber=e,t.disableLeft=o,t.disableRight=c},selectCurrentImage:e=>{e&&e.stopPropagation();const t=r.imageIndex+1;s.selectImage(t)},selectNextImage:e=>{e&&e.stopPropagation();const{selectedImageNumber:t,imageIds:o}=a(),n=Math.min(o.length,t+1);s.selectImage(n)},selectPreviousImage:e=>{e&&e.stopPropagation();const{selectedImageNumber:t}=a(),o=Math.max(1,t-1);s.selectImage(o)},onSelectedLargeImageKeyDown:e=>{(r.isSelected&&"Enter"===e.code||"Space"===e.code||"NumpadEnter"===e.code)&&("Space"===e.code&&e.preventDefault(),s.openDialog())},onViewAllImagesKeyDown:e=>{"Enter"!==e.code&&"Space"!==e.code&&"NumpadEnter"!==e.code||("Space"===e.code&&e.preventDefault(),s.openDialog())},onThumbnailKeyDown:e=>{"Enter"!==e.code&&"Space"!==e.code&&"NumpadEnter"!==e.code||("Space"===e.code&&e.preventDefault(),s.selectCurrentImage())},onDialogKeyDown:e=>{"Escape"===e.code&&s.closeDialog()},openDialog:()=>{a().isDialogOpen=!0,document.body.classList.add("wc-block-product-gallery-dialog-open")},closeDialog:()=>{a().isDialogOpen=!1,document.body.classList.remove("wc-block-product-gallery-dialog-open")},onTouchStart:e=>{const t=a(),{clientX:o}=e.touches[0];t.touchStartX=o,t.touchCurrentX=o,t.isDragging=!0},onTouchMove:e=>{const t=a();if(!t.isDragging)return;const{clientX:o}=e.touches[0];t.touchCurrentX=o,e.preventDefault()},onTouchEnd:()=>{const e=a();if(!e.isDragging)return;const t=e.touchCurrentX-e.touchStartX,n=(0,o.getElement)()?.ref,c=n?.offsetWidth||0;Math.abs(t)>.2*c&&(t>0&&!e.disableLeft?s.selectPreviousImage():t<0&&!e.disableRight&&s.selectNextImage()),e.isDragging=!1,e.touchStartX=0,e.touchCurrentX=0}},callbacks:{watchForChangesOnAddToCartForm:()=>{const e=a(),t=document.querySelector(`form[data-product_id="${e.productId}"]`);if(!t)return;const o=t=>{const{disableLeft:o,disableRight:a}=n(t,e.imageIds.length);e.selectedImageNumber=t,e.disableLeft=o,e.disableRight=a},c=()=>o(1),r=new MutationObserver((function(t){for(const a of t){const t=a.target.getAttribute("current-image");if("attributes"===a.type&&t&&e.imageIds.includes(t)){const a=e.imageIds.indexOf(t)+1;o(a)}else c()}}));r.observe(t,{attributes:!0});const s=document.querySelector(".wp-block-add-to-cart-form .reset_variations");return s&&s.addEventListener("click",c),()=>{r.disconnect(),document.removeEventListener("click",c)}},dialogStateChange:()=>{const{selectedImageNumber:e,isDialogOpen:t}=a(),{ref:n}=(0,o.getElement)()||{};if(t&&n instanceof HTMLElement){n.focus();const t=n.querySelector(`[data-image-index="${e}"]`);t instanceof HTMLElement&&(t.scrollIntoView({behavior:"auto",block:"center"}),t.focus())}}}},{state:r,actions:s}=(0,o.store)("woocommerce/product-gallery",c,{lock:!0});var i,l;