class ProductModal extends ModalDialog{constructor(){super(),this.sliderInstance=new Swiper(this.querySelector("[data-modal-slider]"),{slidesPerView:1,navigation:{prevEl:this.querySelector(".swiper-button--prev"),nextEl:this.querySelector(".swiper-button--next")},on:{slideChangeTransitionEnd:swiper=>{this.playActiveSlideVideo(swiper)}}})}show(opener){if(this.openedBy=opener,this.setAttribute("open",""),trapFocus(this,this.dialogHolder),window.pauseAllMedia(),opener.hasAttribute("data-model-opener")){this.showActiveMedia(opener.dataset.mediaId);return}this.showActiveMedia()}hide(){document.body.dispatchEvent(new CustomEvent("modalClosed")),this.removeAttribute("open"),removeTrapFocus(this.openedBy),window.pauseAllMedia()}connectedCallback(){document.addEventListener("click",event=>{(!this.openedBy||!this.contains(event.target)&&!this.openedBy.contains(event.target))&&this.hide()})}showActiveMedia(activeMedia="videos"){if(activeMedia!=="videos"){const activeMediaId=this.openedBy.getAttribute("data-media-id"),activeMedia2=this.querySelector(`[data-media-id="${activeMediaId}"]`);activeMedia2?.loadContent(),activeMedia2.parentElement.classList.add("swiper-slide"),activeMedia2.parentElement.classList.remove("hidden"),this.querySelectorAll("[data-media-id]").forEach(media=>{media!==activeMedia2&&(media.parentElement.classList.remove("swiper-slide"),media.parentElement.classList.add("hidden"))}),this.sliderInstance.update();return}this.querySelectorAll("[data-media-id]").forEach(media=>{if(media.tagName.toLowerCase()==="product-model"){media.parentElement.classList.remove("swiper-slide"),media.parentElement.classList.add("hidden");return}media.parentElement.classList.add("swiper-slide"),media.parentElement.classList.remove("hidden")}),this.querySelector("[data-media-id]:not(.hidden [data-media-id])").loadContent()}hide(){super.hide(),pauseAllMedia();const activeModel=this.querySelector(".swiper-slide-active product-model");activeModel&&(activeModel.removeAttribute("loaded"),activeModel.querySelector(".shopify-model-viewer-ui")?.remove())}playActiveSlideVideo(swiper){pauseAllMedia(),swiper.slides.filter(sliderSlide=>sliderSlide.classList.contains("swiper-slide-active"))[0].querySelector("deferred-media").loadContent()}}customElements.define("product-modal",ProductModal);
//# sourceMappingURL=/cdn/shop/t/12/assets/product-modal.js.map?v=148142618907775268591682758932
