1(function(){"use strict";function getGiftIds(flow){const script=flow.querySelector("script[data-gift-picker-ids]");if(!script)return[];try{const ids=JSON.parse(script.textContent||"[]");return Array.isArray(ids)?ids.map(String):[]}catch{return[]}}document.addEventListener("click",function(e){if(!(e.target instanceof Element))return;const dismiss=e.target.closest("[data-gift-dismiss]");if(!dismiss)return;const slide=dismiss.closest("[data-gift-slide]");if(!slide)return;const tier=slide.getAttribute("data-gwp-tier");if(tier){const bar=document.querySelector('free-shipping-bar[data-gwp-tier="'+tier+'"]');bar&&bar.remove()}slide.remove()}),document.addEventListener("click",function(e){if(!(e.target instanceof Element))return;const toggle=e.target.closest("[data-gift-select-toggle]");if(!toggle)return;const flow=toggle.closest("[data-gift-flow]");if(!flow)return;const banner=flow.querySelector("[data-gift-banner]"),panel=flow.querySelector("[data-gift-picker-panel]");if(!banner||!panel)return;if(panel.hasAttribute("hidden")){panel.removeAttribute("hidden"),banner.setAttribute("hidden","");const track=panel.querySelector("[data-gift-carousel-track]");track instanceof HTMLElement&&syncCarouselState(track)}else panel.setAttribute("hidden",""),banner.removeAttribute("hidden")}),document.addEventListener("click",function(e){if(!(e.target instanceof Element))return;const arrow=e.target.closest("[data-gift-carousel-prev], [data-gift-carousel-next]");if(!arrow)return;const carousel=arrow.closest("[data-gift-carousel]"),track=carousel&&carousel.querySelector("[data-gift-carousel-track]");if(!(track instanceof HTMLElement))return;const firstSlide=track.firstElementChild;if(!(firstSlide instanceof HTMLElement))return;const gapValue=window.getComputedStyle(track).columnGap||window.getComputedStyle(track).gap||"0",step=firstSlide.getBoundingClientRect().width+(parseFloat(gapValue)||0),direction=arrow.hasAttribute("data-gift-carousel-prev")?-1:1;track.scrollBy({left:direction*step,behavior:"smooth"})});function syncCarouselState(track){const carousel=track.closest("[data-gift-carousel]"),progressRow=carousel&&carousel.parentElement.querySelector("[data-gift-total]");if(!(progressRow instanceof HTMLElement))return;const total=parseInt(progressRow.dataset.giftTotal||"",10),firstSlide=track.firstElementChild;if(!total||!(firstSlide instanceof HTMLElement))return;const gapValue=window.getComputedStyle(track).columnGap||window.getComputedStyle(track).gap||"0",step=firstSlide.getBoundingClientRect().width+(parseFloat(gapValue)||0);if(!step)return;const maxScroll=track.scrollWidth-track.clientWidth,atStart=track.scrollLeft<=1,atEnd=maxScroll<=0||track.scrollLeft>=maxScroll-1;let current;if(atEnd)current=total;else{const rightEdge=track.scrollLeft+track.clientWidth;current=Math.max(1,Math.min(total,Math.round(rightEdge/step)))}const currentEl=progressRow.querySelector("[data-gift-counter-current]");currentEl&&(currentEl.textContent=String(current));const fillEl=progressRow.querySelector("[data-gift-progress-fill]");if(fillEl instanceof HTMLElement){const progress=current/total;fillEl.style.width=(progress*100).toFixed(2)+"%"}if(carousel instanceof HTMLElement){const prevBtn=carousel.querySelector("[data-gift-carousel-prev]"),nextBtn=carousel.querySelector("[data-gift-carousel-next]");prevBtn instanceof HTMLButtonElement&&(prevBtn.disabled=atStart),nextBtn instanceof HTMLButtonElement&&(nextBtn.disabled=atEnd)}}function syncAllCarousels(){document.querySelectorAll("[data-gift-carousel-track]").forEach(syncCarouselState)}document.addEventListener("scroll",function(e){const track=e.target;!(track instanceof HTMLElement)||!track.matches("[data-gift-carousel-track]")||syncCarouselState(track)},!0),syncAllCarousels(),document.documentElement.addEventListener("cart:change",syncAllCarousels);function getCartSectionIds(){const sectionIds=[];return document.documentElement.dispatchEvent(new CustomEvent("cart:prepare-bundled-sections",{bubbles:!0,detail:{sections:sectionIds}})),sectionIds}function dispatchGiftCartChange(cart,sections){cart.sections=sections||{},document.documentElement.dispatchEvent(new CustomEvent("cart:change",{bubbles:!0,detail:{baseEvent:"variant:add",cart,s
1ourceId:"gift-picker"}}))}function isCartPage(){const settings=window.themeVariables&&window.themeVariables.settings;return!!settings&&(settings.cartType==="page"||settings.pageType==="cart")}async function removeGifts(items,giftIds){const toRemove=items.filter(function(item){return giftIds.indexOf(String(item.product_id))!==-1&&item.properties&&item.properties._is_gwp==="true"});if(!toRemove.length)return null;const sectionIds=getCartSectionIds();let lastResult=null;for(const item of toRemove){const payload={id:item.key,quantity:0};item===toRemove[toRemove.length-1]&§ionIds.length&&(payload.sections=sectionIds.join(","),payload.sections_url=window.location.pathname),lastResult=await(await fetch(`${Shopify.routes.root}cart/change.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(payload)})).json()}return lastResult}async function handleGiftFormSubmit(form){const flow=form.closest("[data-gift-flow]"),giftIds=flow?getGiftIds(flow):[],submitBtn=form.querySelector('[type="submit"]');if(submitBtn instanceof HTMLButtonElement){if(submitBtn.disabled)return;submitBtn.setAttribute("aria-busy","true")}try{if(giftIds.length){const cart=await(await fetch(`${Shopify.routes.root}cart.js`)).json();await removeGifts(cart.items,giftIds)}if(isCartPage()){form.submit();return}const sectionIds=getCartSectionIds(),formData=new FormData(form);sectionIds.length&&(formData.set("sections",sectionIds.join(",")),formData.set("sections_url",window.location.pathname));const addRes=await fetch(`${Shopify.routes.root}cart/add.js`,{method:"POST",headers:{"X-Requested-With":"XMLHttpRequest"},body:formData}),addData=await addRes.json();if(!addRes.ok){form.dispatchEvent(new CustomEvent("cart:error",{bubbles:!0,detail:{error:addData.description||addData.message}})),document.dispatchEvent(new CustomEvent("cart:refresh"));return}const cartContent=await(await fetch(`${Shopify.routes.root}cart.js`)).json();dispatchGiftCartChange(cartContent,addData.sections)}catch(err){console.error("[gift-picker] swap/add error:",err)}finally{submitBtn instanceof HTMLButtonElement&&submitBtn.removeAttribute("aria-busy")}}document.addEventListener("click",function(e){if(!(e.target instanceof Element))return;const submitBtn=e.target.closest('[type="submit"]');if(!submitBtn||!submitBtn.closest("[data-gift-carousel]"))return;const form=submitBtn.form;form instanceof HTMLFormElement&&(e.preventDefault(),e.stopPropagation(),handleGiftFormSubmit(form))},!0),document.addEventListener("submit",function(e){e.target instanceof HTMLFormElement&&e.target.closest("[data-gift-carousel]")&&(e.preventDefault(),e.stopPropagation(),handleGiftFormSubmit(e.target))},!0),document.documentElement.addEventListener("cart:change",function(e){if(e.detail&&e.detail.sourceId==="gift-picker")return;const cart=e.detail&&e.detail.cart;!cart||!Array.isArray(cart.items)||document.querySelectorAll("[data-gift-flow]").forEach(function(flow){const giftIds=getGiftIds(flow);if(!giftIds.length)return;const matches=cart.items.filter(function(item){return giftIds.indexOf(String(item.product_id))!==-1&&item.properties&&item.properties._is_gwp==="true"});if(matches.length<2)return;const toRemove=matches.slice(0,-1).map(function(item){return item.key});(async function(){const result=await removeGifts(cart.items.filter(function(item){return toRemove.indexOf(item.key)!==-1}),giftIds),cartContent=await(await fetch(`${Shopify.routes.root}cart.js`)).json();dispatchGiftCartChange(cartContent,result&&result.sections)})()})});function getGwpTiers(){const tiers=[];return document.querySelectorAll("script[data-gwp-gift-ids]").forEach(function(script){let ids;try{ids=JSON.parse(script.textContent||"[]")}catch{return}if(!Array.isArray(ids)||!ids.length)return;const threshold=parseFloat(script.getAttribute("data-gwp-threshold")||"");if(!threshold)return;const customerOnly=script.getAttribute("data-gwp-customer-only")==="true";tiers.push({ids:ids.map(String),threshold,customerOnly})}),tiers}function computeQualifyingSubtotal(cart,giftIds){let total=0,gwpPrice=0;
1cart.items.forEach(function(item){item.requires_shipping&&(total+=item.final_line_price),giftIds.indexOf(String(item.product_id))!==-1&&item.properties&&item.properties._is_gwp==="true"&&(gwpPrice+=item.final_line_price)});const discount=(cart.cart_level_discount_applications||[]).reduce(function(sum,discountApplication){return sum+discountApplication.total_allocated_amount},0);return total-discount-gwpPrice}function removeGiftsForTiers(cart,shouldRemove){!cart||!Array.isArray(cart.items)||getGwpTiers().forEach(function(tier){if(!shouldRemove(tier))return;const toRemove=cart.items.filter(function(item){return tier.ids.indexOf(String(item.product_id))!==-1&&item.properties&&item.properties._is_gwp==="true"});toRemove.length&&(async function(){const result=await removeGifts(toRemove,tier.ids),cartContent=await(await fetch(`${Shopify.routes.root}cart.js`)).json();dispatchGiftCartChange(cartContent,result&&result.sections)})()})}function checkGwpTiers(cart){if(!cart)return;const loggedIn=!!(window.customer&&window.customer.id);removeGiftsForTiers(cart,function(tier){const belowThreshold=computeQualifyingSubtotal(cart,tier.ids)<tier.threshold,customerLoggedOut=tier.customerOnly&&!loggedIn;return belowThreshold||customerLoggedOut})}document.documentElement.addEventListener("cart:change",function(e){checkGwpTiers(e.detail&&e.detail.cart)}),isCartPage()&&fetch(`${Shopify.routes.root}cart.js`).then(function(res){return res.json()}).then(checkGwpTiers).catch(function(err){console.error("[gift-picker] initial threshold check failed:",err)}),fetch(`${Shopify.routes.root}cart.js`).then(function(res){return res.json()}).then(function(cart){window.customer&&window.customer.id||removeGiftsForTiers(cart,function(tier){return tier.customerOnly})}).catch(function(err){console.error("[gift-picker] initial customer-only check failed:",err)})})(); 2//# sourceMappingURL=/cdn/shop/t/153/assets/gift-picker.js.map?v=3702315453246804001790142838
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.