import{Segment}from"@dna/analytics";import{RespondToViewport,WithProfiler}from"@dna/mixins";import*as paths from"@dna/paths";import styles from"@dna/styles";import{debounce,getSectionPosition,igGetExperimentControl}from"@dna/utils";import{LitElement,classMap,css,html,nothing,unsafeHTML,when}from"@lit";class DNAProductCarousel extends WithProfiler(RespondToViewport(LitElement)){static properties={experimentationTrackingKey:{type:String,attribute:"experimentation-tracking-key"},trackingKey:{type:String,attribute:"tracking-key"},numberOfProducts:{type:Number,attribute:"number-of-products"},items:{type:Array},sectionSettings:{type:Array},customConstructorItemName:{type:String,attribute:"custom-constructor-item-name"},activeSlide:{type:Number,state:!0},productAlignment:{type:String,attribute:"product-alignment"},slidesPerPageOverride:{type:Function},applyTest1218:{type:Boolean}};constructor(){super(),this.items=[],this.displayName="",this.sectionSettings=[],this.carouselSlidePosition=0,this.slideChangedOnLoad=!1,this.activeSlide=0,this.productAlignment="center",this.applyTest1218=!1}get maxItems(){return this.numberOfProducts||20}get filteredItems(){let filtered=this.items?this.items.filter(item=>item!==null):[];return this.sectionSettings.hide_out_of_stock_products&&(filtered=filtered.filter(item=>item.available)),filtered.slice(0,this.maxItems)}get headlineAlignment(){return this.sectionSettings?.headline_alignment}get headline(){return this.sectionSettings?.headline}get subline(){return this.sectionSettings?.subline}get ctaText(){return this.sectionSettings?.cta_text}get ctaUrl(){return this.sectionSettings?.cta_url}get showSubline(){return!!subline||!!ctaText&&!!ctaUrl}get showNavigation(){return this.filteredItems.length>4&&!this.isMobile}get slidesPerPage(){return this.slidesPerPageOverride?this.slidesPerPageOverride(this.viewport):this.viewport==="widescreen"||this.viewport==="desktop"?5.25:this.viewport==="tablet"?4.25:1.75}connectedCallback(){super.connectedCallback(),this.$section=this.closest(".shopify-section"),this.sectionPosition=getSectionPosition(this.$section),this.addEventListener("sl-slide-change",debounce(e=>{this._handleSlideChangeOnLoad(e)},250)),this.slideChangeOnLoadHandled=!1,this.experimentationTrackingKey?.length&&this.$section.setAttribute("data-experiment-selector",this.experimentationTrackingKey),(async()=>{const isTECH1218Control=await igGetExperimentControl({staging:"da7ce578-6b06-4acb-8cc2-e44f124bc26f",production:"b45702d3-2ecb-4694-8331-5eb25fef53cf"});this.applyTest1218=!1,!isTECH1218Control&&this.isMobile&&(this.applyTest1218=!0)})()}_handleSlideChangeOnLoad=event=>{event.detail.index<=0&&!this.slideChangeOnLoadHandled&&(this.slideChangedOnLoad=!0,this.slideChangeOnLoadHandled=!0),this.activeSlide=event.detail.index,this.slideChangedOnLoad?this.slideChangedOnLoad=!1:this._trackCarouselScrolled(event)};_trackCarouselScrolled=event=>{Segment.protect(()=>{if(this.slideChangedOnLoad)this.slideChangedOnLoad=!1;else{const $carouselSectionTitle=event.target.renderRoot.querySelector(".js-product-carousel-headline"),scrollDirection=event.detail.index>this.carouselSlidePosition?"next":"previous";this.carouselSlidePosition=event.detail.index,Segment.track(Segment.CONSTANTS.EVENTS.PRODUCT_CAROUSEL_SCROLLED,{product_carousel_section_title:$carouselSectionTitle?.textContent.trim(),product_carousel_scroll_direction:scrollDirection,product_carousel_pod_id:this.dataset.cnstrcRecommendationsPodId,section_page_position:this.sectionPosition,section_tracking_key:this.trackingKey})}})};_trackCarouselCTAClicked=event=>{Segment.protect(()=>{const $carouselSectionTitle=event.target.closest("dna-product-carousel").renderRoot.querySelector(".js-product-carousel-headline"),$clickedProductCarouselCTA=event.target.closest("sl-button");Segment.track(Segment.CONSTANTS.EVENTS.PRODUCT_CAROUSEL_CTA_CLICKED,{product_carousel_section_title:$carouselSectionTitle?.textContent.trim(),product_carousel_cta_link:$clickedProductCarouselCTA.getAttribute("href"),product_carousel_cta_text:$clickedProductCarouselCTA.textContent.trim(),product_carousel_pod_id:this.dataset.cnstrcRecommendationsPodId,section_page_position:this.sectionPosition,section_tracking_key:this.trackingKey})})};_renderHeader(){const showSubline=!!this.subline||!!this.ctaText&&!!this.ctaUrl;return html` ${when(this.headline,()=>html`