1(function(){"use strict";const SELECTORS={panel:"[data-recommendations-panel]",list:"[data-recommendations-list]",mobilePanel:"[data-recommendations-mobile]",mobileList:"[data-recommendations-mobile-list]"};class CartDrawerRecommendations{constructor(){this.cache=null,this.cacheKey=null,document.addEventListener("click",e=>{const btn=e.target.closest("[data-add-recommended]");btn&&(e.preventDefault(),this.addToCart(btn.dataset.variantId,btn))}),this.fetchRecommendations(),this.subscribeToPubSub();var drawerEl=document.querySelector("cart-drawer");if(drawerEl){var self=this,classObserver=new MutationObserver(function(mutations){for(var i=0;i<mutations.length;i++)if(mutations[i].attributeName==="class"&&drawerEl.classList.contains("active")){self.fetchRecommendations();break}});classObserver.observe(drawerEl,{attributes:!0,attributeFilter:["class"]})}this._innerObserver=null,this._innerDebounce=null,this.setupInnerObserver()}setupInnerObserver(){this._innerObserver&&this._innerObserver.disconnect();var drawerInner=document.querySelector(".drawer__inner");if(drawerInner){var self=this;this._innerObserver=new MutationObserver(function(){var drawer=document.querySelector("cart-drawer");!drawer||!drawer.classList.contains("active")||(clearTimeout(self._innerDebounce),self._innerDebounce=setTimeout(function(){self.cache=null,self.cacheKey=null,self.fetchRecommendations()},300))}),this._innerObserver.observe(drawerInner,{childList:!0})}}subscribeToPubSub(){var self=this,trySubscribe=function(){typeof subscribe=="function"&&typeof PUB_SUB_EVENTS<"u"?subscribe(PUB_SUB_EVENTS.cartUpdate,function(){self.showLoader(),setTimeout(function(){self.showLoader()},300),setTimeout(function(){self.cache=null,self.cacheKey=null,self.fetchRecommendations()},600)}):setTimeout(trySubscribe,100)};trySubscribe()}showLoader(){if(this.getElements()){this.forceVisible();var loaderHtml=this.createLoaderElement();this.list.innerHTML="",this.list.appendChild(loaderHtml.cloneNode(!0)),this.mobileList&&(this.mobileList.innerHTML="",this.mobileList.appendChild(loaderHtml.cloneNode(!0)));var inlineList=document.querySelector("[data-recommendations-inline-list]");inlineList&&(inlineList.innerHTML="",inlineList.appendChild(loaderHtml.cloneNode(!0)))}}createLoaderElement(){var wrapper=document.createElement("div");wrapper.style.cssText="display:flex;align-items:center;justify-content:center;height:100%;width:100%;padding:30px 0;";var svg=document.createElementNS("http://www.w3.org/2000/svg","svg");if(svg.setAttribute("viewBox","0 0 200 200"),svg.setAttribute("width","40"),svg.setAttribute("height","40"),svg.style.cssText="animation:recSpin 2s linear infinite;",svg.innerHTML='<defs><radialGradient id="recSpinGrad" cx=".66" fx=".66" cy=".3125" fy=".3125" gradientTransform="scale(1.5)"><stop offset="0" stop-color="#333333"/><stop offset=".3" stop-color="#333333" stop-opacity=".9"/><stop offset=".6" stop-color="#333333" stop-opacity=".6"/><stop offset=".8" stop-color="#333333" stop-opacity=".3"/><stop offset="1" stop-color="#333333" stop-opacity="0"/></radialGradient></defs><circle fill="none" opacity=".2" stroke="#333333" stroke-width="15" stroke-linecap="round" cx="100" cy="100" r="70"/><circle fill="none" stroke="url(#recSpinGrad)" stroke-width="15" stroke-linecap="round" stroke-dasharray="200 1000" cx="100" cy="100" r="70"/>',!document.getElementById("recSpinStyle")){var style=document.createElement("style");style.id="recSpinStyle",style.textContent="@keyframes recSpin{to{transform:rotate(360deg)}}",document.head.appendChild(style)}return wrapper.appendChild(svg),wrapper}forceVisible(){if(this.panel){var drawerEl=document.querySelector("cart-drawer");drawerEl&&drawerEl.classList.contains("active")&&(this.panel.style.transition="none",this.panel.style.opacity="1",this.panel.style.transform="translateX(0)")}}getElements(){return this.panel=document.querySelector(SELECTORS.panel),this.panel?(this.list=this.panel.querySelector(SELECTORS.list),this.mobilePanel=document.querySelector(SELECTORS.mobilePanel),this.mobileList=this.mobilePanel?this.mobilePanel.querySelector(SELECTORS.mobileList):null,this.limit=parseInt(this.panel.dataset.limit||"6",10),this.addText=this.panel.dataset.addText||"+ Add",this.moneyFormat=this.panel.dataset.moneyFormat||"${{amount}}",this.scrollableMobile=this.panel.dataset.recommendationsScrollableMobile==="true",!!this.list):!1}async fetchRecommendations(){if(this.getElements()){this.forceVisible();try{const cart=await(await fetch("/cart.js")).json();if(!this.getElements())return;if(this.forceVisible(),cart.item_count===0){this.list.innerHTML="",this.mobileList&&(this.mobileList.innerHTML=""),this.panel.style.display="none",this.mobilePanel&&(this.mobilePanel.style.display="none");var inlineHide=document.querySelector("[data-recommendations-inline]");inlineHide&&(inlineHide.style.display="none");return}this.panel.style.removeProperty("display"),this.mobilePanel&&this.mobilePanel.style.removeProperty("display"),this.ensureInlineRecommendations();const cartProductIds=cart.items.map(item=>item.product_id),cacheKey=cartProductIds.sort().join(",");if(this.cacheKey===cacheKey&&this.cache){this.render(this.cache,cartProductIds);return}this.list.innerHTML='<div class="cart-drawer-recommendations__loader"></div>';const fetchPromises=cart.items.map(item=>fetch("/recommendations/products.json?product_id="+item.product_id+"&limit="+this.limit).then(r=>r.json()).then(data=>data.products||[]).catch(()=>[])),allProducts=(await Promise.all(fetchPromises)).flat(),seen=new Set,uniqueProducts=[];for(const product of allProducts)!seen.has(product.id)&&!cartProductIds.includes(product.id)&&
1(seen.add(product.id),uniqueProducts.push(product));const limitedProducts=uniqueProducts.slice(0,this.limit);this.cache=limitedProducts,this.cacheKey=cacheKey,this.render(limitedProducts,cartProductIds)}catch(error){console.error("[Cart Recommendations] Error fetching:",error)}this.setupInnerObserver()}}render(products,cartProductIds){if(!this.getElements())return;if(this.forceVisible(),!products||products.length===0){this.list.innerHTML="",this.mobileList&&(this.mobileList.innerHTML="");var inlineEmpty=document.querySelector("[data-recommendations-inline]");inlineEmpty&&(inlineEmpty.style.display="none"),this.syncInlineRecommendations();return}const filtered=cartProductIds?products.filter(p=>!cartProductIds.includes(p.id)):products;if(filtered.length===0){this.list.innerHTML="",this.mobileList&&(this.mobileList.innerHTML="");var inlineNone=document.querySelector("[data-recommendations-inline]");inlineNone&&(inlineNone.style.display="none"),this.syncInlineRecommendations();return}this.list.innerHTML=filtered.map(product=>this.renderDesktopCard(product)).join(""),this.mobileList&&(this.mobileList.innerHTML=filtered.map(product=>this.renderMobileCard(product)).join("")),this.ensureInlineRecommendations();var inlineRec=document.querySelector("[data-recommendations-inline]");inlineRec&&inlineRec.style.removeProperty("display"),this.syncInlineRecommendations()}ensureInlineRecommendations(){var cartDrawerItems=document.querySelector("cart-drawer-items");if(cartDrawerItems){var inline=cartDrawerItems.querySelector("[data-recommendations-inline]");if(!inline){inline=document.createElement("div"),inline.className="cart-drawer-recommendations-inline",inline.setAttribute("data-recommendations-inline",""),this.mobilePanel&&(inline.style.cssText=this.mobilePanel.style.cssText),inline.style.display="none";var titleEl=this.panel?this.panel.querySelector(".cart-drawer-recommendations__title"):null,titleText=titleEl?titleEl.textContent.trim():"You may also like";inline.innerHTML='<h3 class="cart-drawer-recommendations-mobile__title">'+this.escapeHtml(titleText)+'</h3><div class="cart-drawer-recommendations-mobile__slider" data-recommendations-inline-list></div>',cartDrawerItems.appendChild(inline)}}}syncInlineRecommendations(){var cartDrawerItems=document.querySelector("cart-drawer-items");if(cartDrawerItems){var inlineList=cartDrawerItems.querySelector("[data-recommendations-inline-list]");inlineList&&this.mobileList&&(inlineList.innerHTML=this.mobileList.innerHTML)}}renderDesktopCard(product){var variant=product.variants&&product.variants[0];if(!variant)return"";var hasComparePrice=product.compare_at_price&&product.compare_at_price>product.price,image=product.featured_image||product.images&&product.images[0];return'<div class="cart-drawer-recommendations__card" data-rec-product-id="'+product.id+'"><div class="cart-drawer-recommendations__card-image">'+(image?'<img src="'+image+'" alt="'+this.escapeHtml(product.title)+'" width="70" height="70" loading="lazy">':"")+'</div><div class="cart-drawer-recommendations__card-info"><h4 class="cart-drawer-recommendations__card-name"><a href="'+product.url+'">'+this.escapeHtml(product.title)+'</a></h4><div class="cart-drawer-recommendations__card-prices">'+(hasComparePrice?'<span class="cart-drawer-recommendations__card-price-compare">'+this.formatMoney(product.compare_at_price)+"</span>":"")+'<span class="cart-drawer-recommendations__card-price'+(hasComparePrice?" cart-drawer-recommendations__card-price--sale":"")+'">'+this.formatMoney(product.price)+'</span></div><button type="button" class="cart-drawer-recommendations__add-btn" data-add-recommended data-variant-id="'+variant.id+'">'+this.escapeHtml(this.addText)+"</button></div></div>"}renderMobileCard(product){var variant=product.variants&&product.variants[0];if(!variant)return"";var hasComparePrice=product.compare_at_price&&product.compare_at_price>product.price,image=product.featured_image||product.images&&product.images[0];return'<div class="cart-drawer-recommendations-mobile__card" data-rec-product-id="'+product.id+'"><div class="cart-drawer-recommendations-mobile__card-image">'+(image?'<img src="'+image+'" alt="'+this.escapeHtml(product.title)+'" width="70" height="70" loading="lazy">':"")+'</div><div class="cart-drawer-recommendations-mobile__card-info"><h4 class="cart-drawer-recommendations-mobile__card-name"><a href="'+product.url+'">'+this.escapeHtml(product.title)+'</a></h4><div class="cart-drawer-recommendations-mobile__card-prices">'+(hasComparePrice?'<span class="cart-drawer-recommendations-mobile__card-price-compare">'+this.formatMoney(product.compare_at_price)+"</span>":"")+'<span class="cart-drawer-recommendations-mobile__card-price'+(hasComparePrice?" cart-drawer-recommendations-mobile__card-price--sale":"")+'">'+this.formatMoney(product.price)+'</span></div><button type="button" class="cart-drawer-recommendations-mobile__card-add-btn" data-add-recommended data-variant-id="'+variant.id+'">'+this.escapeHtml(this.addText)+"</button></div></div>"}async addToCart(variantId,buttonEl){if(variantId){var card=buttonEl.closest(".cart-drawer-recommendations__card")||buttonEl.closest(".cart-drawer-recommendations-mobile__card");
1buttonEl.classList.add("is-loading"),card&&card.classList.add("is-loading");try{var response=await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({id:parseInt(variantId,10),quantity:1})});if(!response.ok){var errorData=await response.json();console.error("[Cart Recommendations] Add error:",errorData.description);return}card&&(card.style.transition="opacity 0.2s ease, transform 0.2s ease",card.style.opacity="0",card.style.transform="translateX(-10px)",setTimeout(function(){card.remove()},200)),this.showLoader(),await this.updateCartDrawerSections(),this.cache=null,this.cacheKey=null,await this.fetchRecommendations()}catch(error){console.error("[Cart Recommendations] Add to cart error:",error)}finally{buttonEl.classList.remove("is-loading"),card&&card.classList.remove("is-loading")}}}async updateCartDrawerSections(){try{var html=await fetch(routes.cart_url+"?section_id=cart-drawer").then(function(r){return r.text()}),doc=new DOMParser().parseFromString(html,"text/html"),sourceEmpty=doc.querySelector("cart-drawer");if(sourceEmpty&&sourceEmpty.classList.contains("is-empty")){window.location.reload();return}for(var selectors=["cart-drawer-items",".cart-drawer__footer",".js-free-shipping"],i=0;i<selectors.length;i++){var target=document.querySelector(selectors[i]),source=doc.querySelector(selectors[i]);target&&source&&target.replaceWith(source)}var bubbleHtml=await fetch(routes.cart_url+"?section_id=cart-icon-bubble").then(function(r){return r.text()}),bubbleDoc=new DOMParser().parseFromString(bubbleHtml,"text/html"),bubbleTarget=document.getElementById("cart-icon-bubble"),bubbleSource=bubbleDoc.querySelector(".shopify-section");bubbleTarget&&bubbleSource&&(bubbleTarget.innerHTML=bubbleSource.innerHTML)}catch(error){console.error("[Cart Recommendations] Section update error:",error)}}formatMoney(cents){if(window.Shopify&&window.Shopify.formatMoney)return window.Shopify.formatMoney(cents,this.moneyFormat);var amount=(cents/100).toFixed(2);return this.moneyFormat.replace(/\{\{\s*amount_with_comma_separator\s*\}\}/g,amount.replace(".",",")).replace(/\{\{\s*amount_no_decimals\s*\}\}/g,Math.floor(cents/100).toString()).replace(/\{\{\s*amount\s*\}\}/g,amount)}escapeHtml(text){var div=document.createElement("div");return div.textContent=text,div.innerHTML}}
1document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){new CartDrawerRecommendations}):new CartDrawerRecommendations})(); 2//# sourceMappingURL=/cdn/shop/t/316/assets/cart-drawer-recommendations.js.map?v=159258899400045056131789750875
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.