const getCurrentCart=async()=>{await fetch("/cart.js").then(res=>res.json()).then(cart=>{window.cart=cart}),window.setGlobalCart()},customerHasTag=tag=>{if(window.ShopifyAnalytics.meta.page.customerId){const customerTags=document.getElementById("header").dataset.customertags;return customerTags!==null&&customerTags.includes(tag)}return!1};async function setSwatchPricePDP(price,priceContainer,productType){window.cart||await getCurrentCart();const{cart}=window,formatPrice=priceToFormat=>`$${(priceToFormat/100).toFixed(priceToFormat%100>0?2:0)}`,setDiscountPrice=(element,originalPrice,salePrice=null)=>{const newPriceElement=element.cloneNode(!0),salePriceHTML=salePrice?` ${salePrice}`:"";newPriceElement.innerHTML=`
${originalPrice}
${salePriceHTML}`,element.replaceWith(newPriceElement)},setFullPrice=(element,priceToFormat)=>{const newPriceElement=element.cloneNode(!0);newPriceElement.innerHTML=formatPrice(priceToFormat),element.replaceWith(newPriceElement)};productType==="swatch"?(()=>{const{maxSwatchesForDiscount}=window,swatchItemsInCart=cart.items.reduce((count,item)=>item.product_type==="Swatch"?count+item.quantity:count,0),swatchDiscountLabel=document.getElementById("swatch-discount-label"),tagsWrapper=document.getElementById("product-label-tags");swatchItemsInCart
Your first ${maxSwatchesForDiscount} swatches are free
`)):(swatchDiscountLabel?.remove(),setFullPrice(priceContainer,price))})():productType==="swatch-book"&&(()=>{const{maxSwatchBooksForDiscount}=window,swatchBooksInCart=cart.items.reduce((count,item)=>item.product_type==="Swatch Book"?count+item.quantity:count,0);!customerHasTag("swatch-book-buyer")&&swatchBooksInCartitem.product_type===productType?count+item.quantity:count,0)>=quantityToDiscount&&(showDiscountPrice=!1),customerHasTag(customerTagToCheck)&&(showDiscountPrice=!1),showDiscountPrice?``:`${product.price}
`}return null}function setSwatchPriceInCarousels(swatchesList2,productType){const{cart}=window,{maxSwatchesForDiscount,maxSwatchBooksForDiscount}=window,quantityToDiscount=productType==="Swatch"?maxSwatchesForDiscount:maxSwatchBooksForDiscount,customerTagToCheck=productType==="Swatch"?"swatch-buyer":"swatch-book-buyer";let showDiscountPrice=!0;cart.items.reduce((count,item)=>item.product_type===productType?count+item.quantity:count,0)>=quantityToDiscount&&(showDiscountPrice=!1),customerHasTag(customerTagToCheck)&&(showDiscountPrice=!1);const utmSwatchCarouselTitle=document.querySelector("utm-swatch-carousel .main-title");utmSwatchCarouselTitle&&(utmSwatchCarouselTitle.textContent=showDiscountPrice?"Free Swatches":"Swatches"),swatchesList2.forEach(product=>{const price=product.querySelector("[data-original-price]").dataset.originalPrice,priceWrapper=product.querySelector(".carousel-item-price");showDiscountPrice?priceWrapper.innerHTML=`
${price}
$0
`:priceWrapper.innerHTML=`${price}`})}const swatchesList=document.querySelectorAll("[data-swatch]"),swatchBooksList=document.querySelectorAll("[data-swatch-book]");swatchesList.length&&document.addEventListener("cartChange",()=>{setSwatchPriceInCarousels(swatchesList,"Swatch")}),swatchBooksList.length&&document.addEventListener("cartChange",()=>{setSwatchPriceInCarousels(swatchBooksList,"Swatch Book")});
//# sourceMappingURL=/cdn/shop/t/2918/assets/swatch-discount.js.map