1const CART_SECTIONS="cart-items,cart-icon-bubble,cart-footer,cart-drawer",LEGACY_AUTO_GIFT_PROPERTY="_cart_offer_auto_gift",AUTO_ADDON_GIFT_PROPERTY="_cart_addon_auto_gift";class CartOfferProgress extends HTMLElement{#syncQueued=!1;connectedCallback(){document.addEventListener("cart:update",this.#handleCartUpdate),this.#queueGiftSync()}disconnectedCallback(){document.removeEventListener("cart:update",this.#handleCartUpdate)}#handleCartUpdate=event=>{const source=event.detail?.data?.source;source==="cart-addon-gift"||source==="cart-auto-gift-cleanup"||event.detail?.data?.didError||this.#queueGiftSync()};#queueGiftSync(){this.#syncQueued||(this.#syncQueued=!0,queueMicrotask(()=>{this.#syncQueued=!1,this.#syncGiftQuantity()}))}async#syncGiftQuantity(){if(window.cartOfferGiftSyncPromise){await window.cartOfferGiftSyncPromise.catch(()=>{}),this.isConnected&&this.#queueGiftSync();return}window.cartOfferGiftSyncPromise=(async()=>{await this.#removeLegacyAutoGiftBoxes(),await this.#reconcileAddonGift()})();try{await window.cartOfferGiftSyncPromise}catch(error){console.error("Unable to remove an auto-added gift box:",error)}finally{window.cartOfferGiftSyncPromise=null}}async#removeLegacyAutoGiftBoxes(){const root=window.Shopify?.routes?.root||"/",cartResponse=await fetch(`${root}cart.js`,{headers:{Accept:"application/json"}});if(!cartResponse.ok)return;const autoGiftLines=(await cartResponse.json()).items.filter(item=>String(item.properties?.[LEGACY_AUTO_GIFT_PROPERTY])==="true");if(autoGiftLines.length!==0){this.#setGiftLoading("removing");try{const updates=Object.fromEntries(autoGiftLines.map(item=>[item.key,0])),response=await fetch(`${root}cart/update.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({updates})});if(!response.ok){const error=await response.json().catch(()=>({}));console.error("Unable to remove the previously auto-added gift box:",error);return}const sectionsResponse=await fetch(`${root}cart?sections=${CART_SECTIONS}`,{headers:{Accept:"application/json"}});if(!sectionsResponse.ok)return;const sections=await sectionsResponse.json();document.dispatchEvent(new CustomEvent("cart:update",{bubbles:!0,detail:{data:{source:"cart-auto-gift-cleanup",sections}}}))}finally{this.#setGiftLoading()}}}async#reconcileAddonGift(){const variantId=Number.parseInt(this.dataset.add
1onGiftVariantId||"",10),threshold=this.#getPresentmentThreshold(this.dataset.addonGiftThreshold);if(!Number.isInteger(variantId)||threshold<=0)return;const root=window.Shopify?.routes?.root||"/",cartResponse=await fetch(`${root}cart.js`,{headers:{Accept:"application/json"}});if(!cartResponse.ok)return;const cart=await cartResponse.json(),giftLines=cart.items.filter(item=>Number(item.variant_id)===variantId),autoGiftLines=giftLines.filter(item=>String(item.properties?.[AUTO_ADDON_GIFT_PROPERTY])==="true"),hasManualGift=giftLines.some(item=>String(item.properties?.[AUTO_ADDON_GIFT_PROPERTY])!=="true"),currentQuantity=autoGiftLines.reduce((total,item)=>total+item.quantity,0),requiredQuantity=this.#getQualifyingSubtotal(cart)>=threshold&&!hasManualGift?1:0;if(!(currentQuantity===requiredQuantity&&autoGiftLines.length<=1)){this.#setGiftLoading(requiredQuantity>currentQuantity?"adding":"removing");try{let response;if(autoGiftLines.length>0){const updates=Object.fromEntries(autoGiftLines.map(item=>[item.key,0]));requiredQuantity>0&&(updates[autoGiftLines[0].key]=requiredQuantity),response=await fetch(`${root}cart/update.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({updates})})}else if(requiredQuantity>0)response=await fetch(`${root}cart/add.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({items:[{id:variantId,quantity:1,properties:{[AUTO_ADDON_GIFT_PROPERTY]:"true"}}]})});else return;if(!response.ok){const error=await response.json().catch(()=>({}));console.error("Unable to synchronize the free bracelet:",error);return}const sectionsResponse=await fetch(`${root}cart?sections=${CART_SECTIONS}`,{headers:{Accept:"application/json"}});if(!sectionsResponse.ok)return;const sections=await sectionsResponse.json();document.dispatchEvent(new CustomEvent("cart:update",{bubbles:!0,detail:{data:{source:"cart-addon-gift",sections}}}))}finally{this.#setGiftLoading()}}}#setGiftLoading(action){const loader=this.querySelector(".cart-offer-progress__loading");loader&&(action?(loader.dataset.action=action,loader.hidden=!1,this.setAttribute("aria-busy","true")):(loader.hidden=!0,loader.removeAttribute("data-action"),this.removeAttribute("aria-busy")))}#getPresentmentThreshold(value){const presentmentCurrencyThreshold=Number.parseInt(value||"0",10);return!Number.isInteger(presentmentCurrencyThreshold)||presentmentCurrencyThreshold<=0?0:presentmentCurrencyThreshold}#getQualifyingSubtotal(cart){const autoGiftTotal=cart.items.reduce((total,item)=>String(item.properties?.[LEGACY_AUTO_GIFT_PROPERTY])==="true"||String(item.properties?.[AUTO_ADDON_GIFT_PROPERTY])==="true"?total+item.final_line_price:total,0);return Math.max(cart.total_price-autoGiftTotal,0)}}customElements.get("cart-offer-progress")||customElements.define("cart-offer-progress",CartOfferProgress); 2//# sourceMappingURL=/cdn/shop/t/115/assets/cart-offer-promotions.js.map?v=8400922333276233621790083539
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.