import{Segment}from"@dna/analytics";import{getSectionPosition,viewportObserver}from"@dna/utils";if(!customElements.get("dna-editorial-multiproduct-carousel")){class DNAEditorialMultiProductCarousel extends HTMLElement{constructor(){super(),this.empcDirection=!1,this.empcPosition=1,this.experimentationTrackingKey=this.getAttribute("experimentation-tracking-key"),this.trackingKey=this.getAttribute("tracking-key")}connectedCallback(){this.$section=this.closest(".shopify-section"),this.sectionPosition=getSectionPosition(this.$section),this.$empcBanner=this.querySelector(".js-empc-banner"),this.$empcHeadings=this.querySelectorAll(".js-empc-heading"),this.$empcCarousel=this.querySelector(".js-empc-content sl-carousel"),this.$empcNavButtons=this.querySelectorAll(".js-empc-navigation button"),this.$empcCtas=this.querySelectorAll(".js-empc-cta"),this.$empcProducts=this.querySelectorAll(".js-empc-product-link"),this.empcHeadings=this.getAttribute("empc-headings").split(";"),this.empcCTAs=this.getAttribute("empc-ctas").split(";"),this.empcCTALinks=this.getAttribute("empc-cta-links").split(";"),this.experimentationTrackingKey?.length&&this.$section.setAttribute("data-experiment-selector",this.experimentationTrackingKey),customElements.whenDefined("sl-carousel").then(()=>{this.$empcCarousel?.goToSlide(0),setTimeout(()=>{this.$empcCarousel?.addEventListener("sl-slide-change",event=>{this.handleSlideChange(event,this.empcDirection)})},500)}),this.addEventListener("click",event=>{(event.target.closest(".js-arrow-prev")||event.target.closest(".js-arrow-next"))&&this.handleSlideChangeClick(event),(event.target.closest(".js-empc-cta")||event.target.closest(".js-empc-banner"))&&this.trackEMPCLinkClick(event),event.target.closest(".js-empc-product-link")&&this.trackEMPCProductClick(event)}),window.innerWidth>768&&this.$empcBanner.hasAttribute("data-animation")&&this.$empcBanner.setAttribute("data-animation","wipeInDown")}handleSlideChangeClick(clickEvent){clickEvent.target.closest("button")?.classList.contains("js-arrow-next")?(this.empcDirection="next",this.$empcCarousel.next()):(this.empcDirection="previous",this.$empcCarousel.previous())}handleSlideChange(slideEvent,slideDirection){this.empcPosition0=slideEvent.detail.index,this.empcPosition=this.empcPosition0+1;const $empcBannerImages=this.$empcBanner?.querySelectorAll(".empc-banner__image-container");if($empcBannerImages.length)for(const image of $empcBannerImages)Number(image.getAttribute("data-slide"))===this.empcPosition0?image.classList.add("active"):image.classList.remove("active");let activeHeading="";this.empcHeadings[this.empcPosition0]&&(activeHeading=this.empcHeadings[this.empcPosition0]);for(const $heading of this.$empcHeadings)$heading.style.opacity=.2,setTimeout(()=>{$heading.innerHTML=activeHeading.trim(),$heading.style.opacity=1},300);const $empcCarouselGrid=this.$empcCarousel?.querySelector("sl-carousel-item.--is-active .js-empc-content-carousel-item-grid");$empcCarouselGrid&&viewportObserver.currentViewport==="mobile"&&($empcCarouselGrid.scrollLeft=0);let activeCTA="",activeCTALink="";this.empcCTAs[this.empcPosition0]&&(activeCTA=this.empcCTAs[this.empcPosition0]),this.empcCTALinks[this.empcPosition0]&&(activeCTALink=this.empcCTALinks[this.empcPosition0]);for(const $cta of this.$empcCtas)$cta.style.opacity=.2,setTimeout(()=>{$cta.textContent=activeCTA.trim(),$cta.href=activeCTALink,$cta.style.opacity=1},300);setTimeout(()=>{this.trackEMPCScroll(slideEvent)},500)}trackEMPCScroll(event){Segment.protect(()=>{const blockTitle=event.target.closest(".editorial-multiproduct-carousel")?.querySelector(".js-empc-heading")?.textContent?.trim();Segment.track(Segment.CONSTANTS.EVENTS.EMPC_SCROLLED,{empc_block_title:blockTitle,empc_scroll_direction:this.empcDirection,empc_carousel_position:this.empcPosition,section_page_position:this.sectionPosition,section_tracking_key:this.trackingKey})})}trackEMPCLinkClick(event){Segment.protect(()=>{const blockTitle=event.target.closest(".editorial-multiproduct-carousel")?.querySelector(".js-empc-heading")?.textContent?.trim(),$clickedEl=event.target.closest(".js-empc-cta")||event.target.closest(".js-empc-banner"),$clickedLink=$clickedEl?.closest("[href]")||$clickedEl?.querySelector("[href]");$clickedLink&&Segment.track(Segment.CONSTANTS.EVENTS.EMPC_LINK_CLICKED,{empc_block_title:blockTitle,empc_cta_text:$clickedEl?.textContent?.trim()||"banner",empc_cta_link:$clickedLink?.getAttribute("href"),empc_carousel_position:this.empcPosition,section_page_position:this.sectionPosition,section_tracking_key:this.trackingKey})})}trackEMPCProductClick(event){Segment.protect(()=>{const blockTitle=event.target.closest(".editorial-multiproduct-carousel")?.querySelector(".js-empc-heading")?.textContent?.trim(),$clickedItem=event.target.closest(".js-empc-product-link");Segment.track(Segment.CONSTANTS.EVENTS.EMPC_PRODUCT_CLICKED,{empc_block_title:blockTitle,empc_clicked_product:$clickedItem?.getAttribute("data-product"),empc_clicked_product_position:Number($clickedItem?.getAttribute("data-index")),empc_carousel_position:this.empcPosition,section_page_position:this.sectionPosition,section_tracking_key:this.trackingKey})})}}customElements.define("dna-editorial-multiproduct-carousel",DNAEditorialMultiProductCarousel)} //# sourceMappingURL=/cdn/shop/t/1163/assets/component-editorial-multiproduct-carousel.js.map?v=25788884678283819391760568441