import{OverflowList}from"@theme/critical";import VariantPicker from"@theme/variant-picker";import{Component}from"@theme/component";import{debounce,isDesktopBreakpoint,mediaQueryLarge,requestYieldCallback}from"@theme/utilities";import{ThemeEvents,SlideshowSelectEvent}from"@theme/events";import{morph}from"@theme/morph";export class ProductCard extends Component{requiredRefs=["productCardLink"];get productPageUrl(){return this.refs.productCardLink.href}getSelectedVariantId(){return this.querySelector('input[type="radio"]:checked[data-variant-id]')?.dataset.variantId||null}getProductCardLink(){return this.refs.productCardLink||null}#fetchProductPageHandler=()=>{this.refs.quickAdd?.fetchProductPage(this.productPageUrl)};#navigateToURL=(event,url)=>{if(event instanceof MouseEvent&&(event.metaKey||event.ctrlKey||event.shiftKey||event.button===1)){event.preventDefault(),window.open(url.href,"_blank");return}else window.location.href=url.href};connectedCallback(){if(super.connectedCallback(),!(this.refs.productCardLink instanceof HTMLAnchorElement))throw new Error("Product card link not found");this.#handleQuickAdd(),this.addEventListener(ThemeEvents.variantUpdate,this.#handleVariantUpdate),this.addEventListener(ThemeEvents.variantSelected,this.#handleVariantSelected),this.addEventListener(SlideshowSelectEvent.eventName,this.#handleSlideshowSelect),mediaQueryLarge.addEventListener("change",this.#handleQuickAdd),this.addEventListener("click",this.navigateToProduct),setTimeout(()=>{this.refs.slideshow?.isNested&&this.#preloadNextPreviewImage()})}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.navigateToProduct)}#preloadNextPreviewImage(){this.refs.slideshow?.slides?.[this.refs.slideshow?.current]?.nextElementSibling?.querySelector('img[loading="lazy"]')?.removeAttribute("loading")}#handleQuickAdd=()=>{this.removeEventListener("pointerenter",this.#fetchProductPageHandler),this.removeEventListener("focusin",this.#fetchProductPageHandler),isDesktopBreakpoint()&&(this.addEventListener("pointerenter",this.#fetchProductPageHandler),this.addEventListener("focusin",this.#fetchProductPageHandler))};#handleVariantSelected=event=>{event.target!==this.variantPicker&&this.variantPicker?.updateSelectedOption(event.detail.resource.id)};#handleVariantUpdate=event=>{event.stopPropagation(),this.updatePrice(event),this.#isUnavailableVariantSelected(event),this.#updateProductUrl(event),this.refs.quickAdd?.fetchProductPage(this.productPageUrl),event.target!==this.variantPicker&&this.variantPicker?.updateVariantPicker(event.detail.data.html),this.#updateVariantImages(),this.#previousSlideIndex=null,this.removeAttribute("data-no-swatch-selected"),this.#updateOverflowList()};#updateOverflowList(){const overflowList=this.querySelector("swatches-variant-picker-component overflow-list"),isActiveOverflowList=!!overflowList?.querySelector('[slot="overflow"]');!overflowList||!isActiveOverflowList||requestAnimationFrame(()=>{overflowList.dispatchEvent(new CustomEvent("reflow",{bubbles:!0,detail:{}}))})}updatePrice(event){const priceContainer=this.querySelectorAll("product-price [ref='priceContainer']")[1],newPriceElement=event.detail.data.html.querySelector("product-price [ref='priceContainer']");newPriceElement&&priceContainer&&morph(priceContainer,newPriceElement)}#updateProductUrl(event){const anchorElement=event.detail.data.html?.querySelector("product-card a"),featuredMediaUrl=event.detail.data.html?.querySelector("product-card-link")?.getAttribute("data-featured-media-url");if(featuredMediaUrl&&this.closest("product-card-link")&&this.closest("product-card-link")?.setAttribute("data-featured-media-url",featuredMediaUrl),anchorElement instanceof HTMLAnchorElement){if(anchorElement.getAttribute("href")?.trim()==="")return;const productUrl=anchorElement.href,{productCardLink,productTitleLink,cardGalleryLink}=this.refs;productCardLink.href=productUrl,cardGalleryLink instanceof HTMLAnchorElement&&(cardGalleryLink.href=productUrl),productTitleLink instanceof HTMLAnchorElement&&(productTitleLink.href=productUrl)}}#isUnavailableVariantSelected(event){const allVariants=event.detail.data.html.querySelectorAll("input:checked");for(const variant of allVariants)this.#toggleAddToCartButton(variant.dataset.optionAvailable==="true")}#toggleAddToCartButton(enable){const addToCartButton=this.querySelector(".add-to-cart__button button");addToCartButton instanceof HTMLButtonElement&&(addToCartButton.disabled=!enable)}#updateVariantImages(){const{slideshow}=this.refs;if(!this.variantPicker?.selectedOption)return;const selectedImageId=this.variantPicker?.selectedOption.dataset.optionMediaId;if(slideshow&&selectedImageId){const{slides=[]}=slideshow.refs;for(const slide of slides)slide.getAttribute("variant-image")!=null&&(slide.hidden=slide.getAttribute("slide-id")!==selectedImageId);slideshow.select({id:selectedImageId},void 0,{animate:!1})}}get allVariants(){return this.querySelectorAll("input[data-variant-id]")}get variantPicker(){return this.querySelector("swatches-variant-picker-component")}#previousSlideIndex=null;#handleSlideshowSelect=event=>{event.detail.userInitiated&&(this.#previousSlideIndex=event.detail.index)};previewVariant(id){const{slideshow}=this.refs;slideshow&&(this.resetVariant.cancel(),slideshow.select({id},void 0,{animate:!1}))}previewImage(event){if(event.pointerType!=="mouse")return;const{slideshow}=this.refs;slideshow&&(this.resetVariant.cancel(),this.#previousSlideIndex!=null&&this.#previousSlideIndex>0?slideshow.select(this.#previousSlideIndex,void 0,{animate:!1}):(slideshow.next(void 0,{animate:!1}),setTimeout(()=>this.#preloadNextPreviewImage())))}resetImage(event){if(event.pointerType!=="mouse")return;const{slideshow}=this.refs;if(this.variantPicker)this.#resetVariant();else{if(!slideshow)return;slideshow.previous(void 0,{animate:!1})}}#resetVariant=()=>{const{slideshow}=this.refs;if(!slideshow)return;if(this.variantPicker?.selectedOption){const id=this.variantPicker.selectedOption.dataset.optionMediaId;if(id){slideshow.select({id},void 0,{animate:!1});return}}const initialSlide=slideshow.initialSlide,slideId=initialSlide?.getAttribute("slide-id");if(initialSlide&&slideshow.slides?.includes(initialSlide)&&slideId){slideshow.select({id:slideId},void 0,{animate:!1});return}slideshow.previous(void 0,{animate:!1})};navigateToProduct=event=>{if(!(event.target instanceof Element)||this.hasAttribute("data-no-navigation")||event.target.closest('button, input, label, select, [tabindex="1"]'))return;const link=this.refs.productCardLink;if(!link.href)return;const linkURL=new URL(link.href),productCardAnchor=link.getAttribute("id");if(!productCardAnchor)return;const url=new URL(window.location.href),parent=this.closest("li");url.hash=productCardAnchor,parent&&parent.dataset.page&&url.searchParams.set("page",parent.dataset.page),window.Shopify.designMode||requestYieldCallback(()=>{history.replaceState({},"",url.toString())}),event.target.closest("a")||this.#navigateToURL(event,linkURL)};resetVariant=debounce(this.#resetVariant,100)}customElements.get("product-card")||customElements.define("product-card",ProductCard);class SwatchesVariantPickerComponent extends VariantPicker{connectedCallback(){super.connectedCallback(),this.parentProductCard=this.closest("product-card"),this.addEventListener(ThemeEvents.variantUpdate,this.#handleCardVariantUrlUpdate.bind(this))}#handleCardVariantUrlUpdate(){if(this.pendingVariantId&&this.parentProductCard instanceof ProductCard){const currentUrl=new URL(this.parentProductCard.refs.productCardLink.href);currentUrl.searchParams.set("variant",this.pendingVariantId),this.parentProductCard.refs.productCardLink.href=currentUrl.toString(),this.pendingVariantId=null}}variantChanged(event){if(!(event.target instanceof HTMLElement))return;const isSwatchInput=event.target instanceof HTMLInputElement&&event.target.name?.includes("-swatch"),clickedSwatch=event.target,availableCount=parseInt(clickedSwatch.dataset.availableCount||"0"),firstAvailableVariantId=clickedSwatch.dataset.firstAvailableOrFirstVariantId;if(isSwatchInput&&availableCount>0&&firstAvailableVariantId){event.stopPropagation(),this.updateSelectedOption(clickedSwatch);const productUrl=this.dataset.productUrl?.split("?")[0];if(!productUrl)return;const url=new URL(productUrl,window.location.origin);url.searchParams.set("variant",firstAvailableVariantId),url.searchParams.set("section_id","section-rendering-product-card");const requestUrl=url.href;this.pendingVariantId=firstAvailableVariantId,this.fetchUpdatedSection(requestUrl);return}super.variantChanged(event)}showAllSwatches(event){event?.preventDefault();const{overflowList}=this.refs;overflowList instanceof OverflowList&&overflowList.showAll()}}customElements.get("swatches-variant-picker-component")||customElements.define("swatches-variant-picker-component",SwatchesVariantPickerComponent); //# sourceMappingURL=/cdn/shop/t/47/assets/product-card.js.map?v=174129639976667491711757451905