var wc;(()=>{"use strict";var e={};(e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})})(e);const t=window.wc.__experimentalInteractivity,o=e=>(0,t.getContext)(e),{state:n,actions:r}=(0,t.store)("woocommerce/product-gallery"),a=e=>{const{isDialogOpen:t}=e;return e[t?"dialogVisibleImagesIds":"visibleImagesIds"]},c=(e,t)=>a(e).indexOf(t),l=(e,t)=>{const o=a(e);e.disableLeft=0===t,e.disableRight=t===o.length-1},i=(e,t)=>{const o=c(e,e.selectedImage);let n=o;"prev"===t&&(n=o-1),"next"===t&&(n=o+1);const r=((e,t)=>{const o=a(e);return t<0?o.at(0)||"":t>o.length-1?o.at(-1)||"":o[t]})(e,n),i=c(e,r);e.selectedImage=r,l(e,i)},s=e=>{var t;e.isDialogOpen=!1,document.body.classList.remove("wc-block-product-gallery-modal-open"),e.elementThatTriggeredDialogOpening&&(null===(t=e.elementThatTriggeredDialogOpening)||void 0===t||t.focus(),e.elementThatTriggeredDialogOpening=null),i(e,"current")},d={state:{get isSelected(){const{selectedImage:e,imageId:t}=o();return e===t},get disableLeft(){return o().disableLeft},get disableRight(){return o().disableRight},get pagerDotFillOpacity(){return n.isSelected?1:.2},get pagerButtonPressed(){return!!n.isSelected},get thumbnailTabIndex(){return n.isSelected?"0":"-1"}},actions:{closeDialog:()=>{const e=o();s(e)},openDialog:()=>{const e=o();e.isDialogOpen=!0,document.body.classList.add("wc-block-product-gallery-modal-open");const t=document.querySelector('dialog[aria-label="Product gallery"]');if(!t)return;t.focus();const n=t.querySelectorAll(".wc-block-product-gallery-large-image-next-previous--button")[0];n&&(i(e,"current"),setTimeout((()=>{n.focus()}),100))},selectImage:()=>{const e=o(),t=c(e,e.imageId);e.selectedImage=e.imageId,l(e,t)},selectNextImage:e=>{e&&e.stopPropagation();const t=o();i(t,"next")},selectPreviousImage:e=>{e&&e.stopPropagation();const t=o();i(t,"prev")},onThumbnailKeyDown:e=>{"Enter"!==e.code&&"Space"!==e.code&&"NumpadEnter"!==e.code||("Space"===e.code&&e.preventDefault(),d.actions.selectImage())},onSelectedLargeImageKeyDown:e=>{if(n.isSelected&&"Enter"===e.code||"Space"===e.code||"NumpadEnter"===e.code){var a;"Space"===e.code&&e.preventDefault(),r.openDialog();const n=null===(a=(0,t.getElement)())||void 0===a?void 0:a.ref;o().elementThatTriggeredDialogOpening=n}},onViewAllImagesKeyDown:e=>{if("Enter"===e.code||"Space"===e.code||"NumpadEnter"===e.code){var n;"Space"===e.code&&e.preventDefault(),r.openDialog();const a=null===(n=(0,t.getElement)())||void 0===n?void 0:n.ref;o().elementThatTriggeredDialogOpening=a}}},callbacks:{watchForChangesOnAddToCartForm:()=>{const e=o(),t=document.querySelector(`form[data-product_id="${e.productId}"]`);if(!t)return;const n=new MutationObserver((function(t){for(const o of t){const t=o.target.getAttribute("current-image");"attributes"===o.type&&t&&e.visibleImagesIds.includes(t)&&(e.selectedImage=t)}}));n.observe(t,{attributes:!0});const r=document.querySelector(".wp-block-add-to-cart-form .reset_variations"),a=()=>{e.selectedImage=e.firstMainImageId};return r&&r.addEventListener("click",a),()=>{n.disconnect(),document.removeEventListener("click",a)}},keyboardAccess:()=>{const e=o();let t=!0;const n=o=>{t&&e.isDialogOpen&&(t=!1,requestAnimationFrame((()=>{t=!0})),"Escape"===o.code&&s(e),"ArrowLeft"===o.code&&d.actions.selectPreviousImage(),"ArrowRight"===o.code&&d.actions.selectNextImage())};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},dialogFocusTrap:()=>{const e=document.querySelector('dialog[aria-label="Product gallery"]');if(!e)return;const t=t=>{if("Tab"===t.code){const o='a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])',n=e.querySelectorAll(o);if(!n.length)return;const r=n[0],a=n[n.length-1];t.shiftKey||t.target!==a||(t.preventDefault(),r.focus()),t.shiftKey&&t.target===r&&(t.preventDefault(),a.focus())}};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t)}}};(0,t.store)("woocommerce/product-gallery",d),(wc=void 0===wc?{}:wc)["product-gallery"]=e})();