1class CartRemoveButton extends HTMLElement{constructor(){super(),this.addEventListener("click",event=>{event.preventDefault(),(this.closest("cart-items")||this.closest("cart-drawer-items")).updateQuantity(this.dataset.index,0,event)})}}customElements.define("cart-remove-button",CartRemoveButton);function updateShippingMessage(cartTotal,container){const shippingWrapper=container.querySelector(".totals--shipping");if(!shippingWrapper)return;const shippingMessage=shippingWrapper.querySelector(".totals__total-value");shippingMessage&&(cartTotal>=6e3?shippingMessage.textContent="Free":shippingMessage.textContent="Calculated at checkout")}class CartItems extends HTMLElement{constructor(){super(),this.lineItemStatusElement=document.getElementById("shopping-cart-line-item-status")||document.getElementById("CartDrawer-LineItemStatus");const debouncedOnChange=debounce(event=>{this.onChange(event)},ON_CHANGE_DEBOUNCE_TIMER);this.addEventListener("change",debouncedOnChange.bind(this))}cartUpdateUnsubscriber=void 0;connectedCallback(){this.cartUpdateUnsubscriber=subscribe(PUB_SUB_EVENTS.cartUpdate,event=>{if(event.source!=="cart-items")return this.onCartUpdate()})}disconnectedCallback(){this.cartUpdateUnsubscriber&&this.cartUpdateUnsubscriber()}resetQuantityInput(id){const input=this.querySelector(`#Quantity-${id}`);input.value=input.getAttribute("value"),this.isEnterPressed=!1}setValidity(event,index,message){event.target.setCustomValidity(message),event.target.reportValidity(),this.resetQuantityInput(index),event.target.select()}validateQuantity(event){const inputValue=parseInt(event.target.value),index=event.target.dataset.index,variantId=event.target.dataset.quantityVariantId;let message="";if(inputValue===0){this.updateQuantity(index,0,event,document.activeElement.getAttribute("name"),variantId);return}const maxAvailable=parseInt(event.target.max);inputValue<event.target.dataset.min||maxAvailable&&inputValue>maxAvailable||inputValue>parseInt(event.target.max)||inputValue%parseInt(event.target.step),message?this.setValidity(event,index,message):(event.target.setCustomValidity(""),event.target.reportValidity(),this.updateQuantity(index,inputValue,event,document.activeElement.getAttribute("name"),variantId))}onChange(event){this.validateQuantity(event)}onCartUpdate(){return this.tagName==="CART-DRAWER-ITEMS"?fetch(`${routes.cart_url}?section_id=cart-drawer`).then(response=>response.text()).then(responseText=>{const html=new DOMParser().parseFromString(responseText,"text/html"),selectors=["cart-drawer-items",".cart-drawer__footer"];for(const selector of selectors){const targetElement=document.querySelector(selector),sourceElement=html.querySelector(selector);targetElement&&sourceElement&&targetElement.replaceWith(sourceElement)}}).catch(e=>{console.error(e)}):fetch(`${routes.cart_url}?section_id=main-cart-items`).then(response=>response.text()).then(responseText=>{const sourceQty=new DOMParser().parseFromString(responseText,"text/html").querySelector("cart-items");this.innerHTML=sourceQty.innerHTML}).catch(e=>{console.error(e)})}getSectionsToRender(){return[{id:"CartDrawer",section:"cart-drawer",selector:".drawer__inner"},{id:"CartMain",section:"cart",selector:".cart-wrapper__inner"}]}updateQuantity(line,quantity,event,name,variantId){const cartDrawer=this.closest("cart-drawer");let recentlyViewedState=null;cartDrawer&&(recentlyViewedState=cartDrawer.saveRecentlyViewedState()),this.enableLoading(line);const body=JSON.stringify({line,quantity,sections:this.getSectionsToRender().map(section=>section.section),sections_url:window.location.pathname}),eventTarget=event.currentTarget instanceof CartRemoveButton?"clear":"change";fetch(`${routes.cart_change_url}`,{...fetchConfig(),body}).then(response=>response.ok?response.text():response.json().then(errorData=>{throw new Error(errorData.description||"Could not update item quantity")})).then(state=>{const parsedState=JSON.parse(state);if(parsedState.status===422)throw new Error(parsedState.description||"You've reached the maximum quantity for this item.");if(parsedState.errors?.length>0)throw new Error(parsedState.description||"You've reached the maximum quantity for this item.");const wasEmpty=document.querySelector("cart-drawer")?.classList.contains("is-empty"),nowEmpty=parsedState.item_count===0;this.classList.toggle("is-empty",nowEmpty);const cartDrawerWrapper=document.querySelector("cart-drawer"),cartFooter=document.getElementById("main-cart-footer");if(cartFooter&&cartFooter.classList.toggle("is-empty",nowEmpty),cartDrawerWrapper&&cartDrawerWrapper.classList.toggle("is-empty",nowEmpty),wasEmpty&&!nowEmpty&&cartDrawerWrapper){fetch(`${routes.cart_url}?section_id=cart-drawer`).then(response=>response.text()).then(html=>{const newDrawerInner=new DOMParser().parseFromString(html,"text/html").querySelector(".drawer__inner"),currentDrawerInner=cartDrawerWrapper.querySelector(".drawer__inner");newDrawerInner&¤tDrawerInner&&(currentDrawerInner.innerHTML=newDrawerInner.innerHTML,cartDrawerWrapper.initCartDrawerAfterUpdate(recentlyViewedState),typeof window.initQuickAddButtons=="function"&&window.initQuickAddButtons(cartDrawerWrapper))}).catch(error=>{console.error("Error refreshing cart drawer:",error)});return}
1this.getSectionsToRender().forEach(section=>{if(section.id==="CartMain"&&!document.getElementById("CartMain"))return;const elementToReplace=document.getElementById(section.id).querySelector(section.selector)||document.getElementById(section.id);elementToReplace.innerHTML=this.getSectionInnerHTML(parsedState.sections[section.section],section.selector)});const updatedValue=parsedState.items[line-1]?parsedState.items[line-1].quantity:void 0;let message="";const quantityElement=document.getElementById(`Quantity-${line}`)||document.getElementById(`Drawer-quantity-${line}`),items=document.querySelectorAll(".cart-item");quantityElement&&items.length===parsedState.items.length&&updatedValue!==parseInt(quantityElement.value)&&(typeof updatedValue>"u"?message=window.cartStrings.error:message=window.cartStrings.quantityError.replace("[quantity]",updatedValue)),this.updateLiveRegions(line,message);const lineItem=document.getElementById(`CartItem-${line}`)||document.getElementById(`CartDrawer-Item-${line}`);lineItem&&lineItem.querySelector(`[name="${name}"]`)?cartDrawerWrapper?trapFocus(cartDrawerWrapper,lineItem.querySelector(`[name="${name}"]`)):lineItem.querySelector(`[name="${name}"]`).focus():parsedState.item_count===0&&cartDrawerWrapper?trapFocus(cartDrawerWrapper.querySelector(".drawer__inner-empty"),cartDrawerWrapper.querySelector("a")):document.querySelector(".cart-item")&&cartDrawerWrapper&&trapFocus(cartDrawerWrapper,document.querySelector(".cart-item__name")),cartDrawer&&recentlyViewedState&&setTimeout(()=>{cartDrawer.restoreRecentlyViewedState(recentlyViewedState)},0),publish(PUB_SUB_EVENTS.cartUpdate,{source:"cart-items",cartData:parsedState,variantId})}).catch(e=>{console.error(e),this.querySelectorAll(".loading__spinner").forEach(overlay=>overlay.classList.add("hidden"));const errors=document.getElementById("cart-errors")||document.getElementById("CartDrawer-CartErrors");errors&&(errors.textContent=e.message||window.cartStrings.error,errors.classList.add("cart-errors--visible"),setTimeout(()=>{errors.classList.remove("cart-errors--visible")},5e3)),window.refreshCart(!1)}).finally(()=>{this.disableLoading(line)})}refreshCartWithValidQuantities(){fetch("/cart.js").then(response=>response.json()).then(cart=>{cart.items.forEach((item,index)=>{const quantityInput=document.querySelector(`#Quantity-${index+1}`)||document.querySelector(`#Drawer-quantity-${index+1}`);if(quantityInput){quantityInput.value=item.quantity,item.variant_inventory_quantity&&quantityInput.setAttribute("max",item.variant_inventory_quantity);const cartItem=quantityInput.closest(".cart-item");if(cartItem&&item.variant_inventory_quantity&&item.variant_inventory_quantity<=5){let stockWarning=cartItem.querySelector(".cart-item__inventory-warning");stockWarning||(stockWarning=document.createElement("div"),stockWarning.classList.add("cart-item__inventory-warning"),cartItem.querySelector(".cart-item__details").appendChild(stockWarning))}}})}).catch(error=>{console.error("Error fetching cart:",error)})}updateLiveRegions(line,message){const lineItemError=document.getElementById(`Line-item-error-${line}`)||document.getElementById(`CartDrawer-LineItemError-${line}`);lineItemError&&(lineItemError.querySelector(".cart-item__error-text").textContent=message),this.lineItemStatusElement.setAttribute("aria-hidden",!0),setTimeout(()=>{},1e3)}getSectionInnerHTML(html,selector){return new DOMParser().parseFromString(html,"text/html").querySelector(selector).innerHTML}enableLoading(line){const mainCartItems=document.getElementById("main-cart-items")||document.getElementById("CartDrawer-CartItems");mainCartItems&&mainCartItems.classList.add("cart__items--disabled");const cartItemElements=this.querySelectorAll(`#CartItem-${line} .loading__spinner`),cartDrawerItemElements=this.querySelectorAll(`#CartDrawer-Item-${line} .loading__spinner`);
1[...cartItemElements,...cartDrawerItemElements].forEach(overlay=>overlay.classList.remove("hidden")),document.activeElement.blur(),this.lineItemStatusElement.setAttribute("aria-hidden",!1)}disableLoading(line){const mainCartItems=document.getElementById("main-cart-items")||document.getElementById("CartDrawer-CartItems");mainCartItems&&mainCartItems.classList.remove("cart__items--disabled");const cartItemElements=this.querySelectorAll(`#CartItem-${line} .loading__spinner`),cartDrawerItemElements=this.querySelectorAll(`#CartDrawer-Item-${line} .loading__spinner`);cartItemElements.forEach(overlay=>overlay.classList.add("hidden")),cartDrawerItemElements.forEach(overlay=>overlay.classList.add("hidden"))}}customElements.define("cart-items",CartItems),customElements.get("cart-note")||customElements.define("cart-note",class extends HTMLElement{constructor(){super(),this.addEventListener("input",debounce(event=>{const body=JSON.stringify({note:event.target.value});fetch(`${routes.cart_update_url}`,{...fetchConfig(),body}).then(()=>CartPerformance.measureFromEvent("note-update:user-action",event))},ON_CHANGE_DEBOUNCE_TIMER))}});function directSwitchToCartTab(drawer){const cartTab=drawer.querySelector(".drawer__tab--cart"),cartContent=drawer.querySelector(".drawer__tab-content--cart"),allTabs=drawer.querySelectorAll(".drawer__tab"),allContent=drawer.querySelectorAll(".drawer__tab-content");cartTab&&cartContent&&(allTabs.forEach(tab=>tab.classList.remove("active")),allContent.forEach(content=>content.classList.remove("active")),cartTab.classList.add("active"),cartContent.classList.add("active"))}function updateCartCounters(itemCount){const cartCounters=document.querySelectorAll(".icon-cart--counter");cartCounters.length>0&&cartCounters.forEach(counter=>{counter.textContent=itemCount,itemCount===0?counter.classList.add("hidden"):counter.classList.remove("hidden")})}class CartDrawer extends HTMLElement{constructor(){super();const recentlyViewed=JSON.parse(localStorage.getItem("recently_viewed")||"[]");this.initialRecentlyViewedCount=Math.min(recentlyViewed.length,10),this.addEventListener("keyup",evt=>evt.code==="Escape"&&this.close()),this.setHeaderCartIconAccessibility(),this.recentlyViewedTabVisible=!1,this.shouldSwitchToCartTab=!1,this.initCartDrawer(),this.cartUpdateUnsubscriber=subscribe(PUB_SUB_EVENTS.cartUpdate,event=>{event.source==="recently-viewed"&&setTimeout(()=>this.switchToCartTab(),100)}),this.cartUpdateListener=subscribe(PUB_SUB_EVENTS.cartUpdate,event=>{setTimeout(()=>{const container=this.querySelector(".drawer__recently-viewed-products-wrapper");container&&(typeof window.initQuickAddButtons=="function"?window.initQuickAddButtons(container):this.initQuickAddButtons(container)),this.shouldSwitchToCartTab&&(this.switchToCartTab(),this.shouldSwitchToCartTab=!1)},200)}),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{this.initializeQuickAddButtons()}):setTimeout(()=>this.initializeQuickAddButtons(),100)}initializeQuickAddButtons(){const container=this.querySelector(".drawer__recently-viewed-products-wrapper");container&&this.initQuickAddButtons(container)}directSwitchToCartTab(){const cartTab=this.querySelector(".drawer__tab--cart"),cartContent=this.querySelector(".drawer__tab-content--cart");cartTab&&cartContent&&(this.querySelectorAll(".drawer__tab").forEach(t=>t.classList.remove("active")),this.querySelectorAll(".drawer__tab-content").forEach(c=>c.classList.remove("active")),cartTab.classList.add("active"),cartContent.classList.add("active"))}disconnectedCallback(){this.cartUpdateUnsubscriber&&this.cartUpdateUnsubscriber(),this.cartUpdateListener&&this.cartUpdateListener()}initCartDrawer(){const overlayElement=document.querySelector(".content-overlay");overlayElement&&overlayElement.addEventListener("click",this.close.bind(this));const closeButton=this.querySelector(".drawer__close");closeButton&&closeButton.addEventListener("click",this.close.bind(this)),this.initTabs(),this.checkRecentlyViewedProducts(),this.querySelectorAll(".cart__continue-button").forEach(button=>{button.addEventListener("click",e=>{e.preventDefault(),this.close()})})}initCartDrawerAfterUpdate(recentlyViewedState){const closeButton=this.querySelector(".drawer__close");closeButton&&closeButton.addEventListener("click",this.close.bind(this)),this.querySelectorAll(".cart__continue-button").forEach(button=>{button.addEventListener("click",e=>{e.preventDefault(),this.close()})}),this.initTabs(),recentlyViewedState?this.restoreRecentlyViewedState(recentlyViewedState):this.checkRecentlyViewedProducts()}onCartUpdate(){return fetch(`${routes.cart_url}?section_id=cart-drawer`).then(response=>response.text()).then(responseText=>{const recentlyViewedState=this.saveRecentlyViewedState(),html=new DOMParser().parseFromString(responseText,"text/html"),drawerInner=this.querySelector(".drawer__inner"),sourceInner=html.querySelector(".drawer__inner");drawerInner&&sourceInner&&(drawerInner.innerHTML=sourceInner.innerHTML,this.initCartDrawerAfterUpdate(recentlyViewedState))}).catch(e=>{console.error(e)})}saveRecentlyViewedState(){const recentlyViewedTab=this.querySelector(".drawer__tab--recently-viewed");return recentlyViewedTab?{visible:!recentlyViewedTab.classList.contains("hidden"),active:recentlyViewedTab.classList.contains("active"),content:this.querySelector(".drawer__recently-viewed-products-wrapper")?.innerHTML||"",loaded:this.querySelector(".drawer__recently-viewed-products-wrapper")?.hasAttribute("data-loaded")||!1}:null}restoreRecentlyViewedState(state){if(!state)return;const recentlyViewedTab=this.querySelector(".drawer__tab--recently-viewed");if(!recentlyViewedTab)return;if(state.visible&&(recentlyViewedTab.classList.remove("hidden"),this.recentlyViewedTabVisible=!0),this.initialRecentlyViewedCount>0){let countElement=recentlyViewedTab.querySelector(".drawer__tab-count");if(countElement)countElement.textContent=this.initialRecentlyViewedCount;else{const countSpan=document.createElement("span");countSpan.className="drawer__tab-count",countSpan.textContent=this.initialRecentlyViewedCount,recentlyViewedTab.appendChild(countSpan)}}if(state.active){this.querySelectorAll(".drawer__tab").forEach(tab=>tab.classList.remove("active")),this.querySelectorAll(".drawer__tab-content").forEach(content=>content.classList.remove("active")),recentlyViewedTab.classList.add("active");const contentElement=this.querySelector(".drawer__tab-content--recently-viewed");contentElement&&contentElement.classList.add("active")}const contentWrapper=this.querySelector(".drawer__recently-viewed-products-wrapper");contentWrapper&&state.loaded&&(contentWrapper.setAttribute("data-loaded","true"),state.content&&(contentWrapper.innerHTML=state.content)),typeof window.initQuickAddButtons=="function"?setTimeout(()=>window.initQuickAddButtons(this),100):setTimeout(()=>this.initQuickAddButtons(this),100),this.initTabs(),this.shouldSwitchToCartTab&&(this.switchToCartTab(),this.shouldSwitchToCartTab=!1)}initTabs(){const tabs=this.querySelectorAll(".drawer__tab");
1tabs.length&&(tabs.forEach(tab=>{const clone=tab.cloneNode(!0);tab.parentNode.replaceChild(clone,tab)}),this.querySelectorAll(".drawer__tab").forEach(tab=>{tab.addEventListener("click",()=>{const tabName=tab.getAttribute("data-tab");this.querySelectorAll(".drawer__tab").forEach(t=>t.classList.remove("active")),this.querySelectorAll(".drawer__tab-content").forEach(c=>c.classList.remove("active")),tab.classList.add("active");const contentElement=this.querySelector(`.drawer__tab-content--${tabName}`);if(contentElement&&contentElement.classList.add("active"),tabName==="recently-viewed"){this.loadRecentlyViewedProducts();const container=this.querySelector(".drawer__recently-viewed-products-wrapper");container&&setTimeout(()=>this.initQuickAddButtons(container),100)}})}))}checkRecentlyViewedProducts(){if(this.initialRecentlyViewedCount>0){const recentlyViewedTab=this.querySelector(".drawer__tab--recently-viewed");if(recentlyViewedTab){if(recentlyViewedTab.classList.remove("hidden"),recentlyViewedTab.querySelector(".drawer__tab-count"))recentlyViewedTab.querySelector(".drawer__tab-count").textContent=this.initialRecentlyViewedCount;else{const countSpan=document.createElement("span");countSpan.className="drawer__tab-count",countSpan.textContent=this.initialRecentlyViewedCount,recentlyViewedTab.appendChild(countSpan)}this.recentlyViewedTabVisible=!0}}}isVariantInCart(variantId){return Array.from(this.querySelectorAll(".cart-item input.quantity__input")).some(input=>input.getAttribute("data-quantity-variant-id")===variantId.toString())}loadRecentlyViewedProducts(){const container=this.querySelector(".drawer__recently-viewed-products-wrapper");if(!container)return;if(container.hasAttribute("data-loaded")){this.updateRecentlyViewedButtonStates();return}let recentlyViewed=JSON.parse(localStorage.getItem("recently_viewed")||"[]");if(recentlyViewed.length===0){container.innerHTML='<p class="empty-state">No recently viewed products</p>';return}const currentPath=window.location.pathname;if(currentPath.includes("/products/")){const currentHandle=currentPath.split("/products/")[1].split("?")[0];recentlyViewed=recentlyViewed.filter(handle=>handle!==currentHandle)}const productHandles=recentlyViewed.slice(0,10);this.initialRecentlyViewedCount=productHandles.length;const recentlyViewedTab=this.querySelector(".drawer__tab--recently-viewed");if(recentlyViewedTab){const countElement=recentlyViewedTab.querySelector(".drawer__tab-count");countElement&&(countElement.textContent=this.initialRecentlyViewedCount)}container.setAttribute("data-loaded","true");try{container.innerHTML='<p class="h5 loading">Loading products...</p>';const productPromises=productHandles.map(handle=>fetch(`${window.Shopify.routes.root}products/${handle}.js`).then(response=>response.json()).catch(error=>(console.error(`Failed to fetch product ${handle}:`,error),null)));Promise.all(productPromises).then(products=>{const validProducts=products.filter(p=>p!==null);validProducts.length>0?(container.innerHTML="",validProducts.forEach(product=>{const isOptical=product.type==="Opticals",isInCart=this.isVariantInCart(product.variants[0].id),productEl=document.createElement("div");productEl.className="drawer__recently-viewed-product",product.type=="Watch"&&productEl.classList.add("drawer__recently-viewed-product--watch"),productEl.innerHTML=` 2 <div class="drawer__recently-viewed-product-image"> 3 <a href="/products/${product.handle}"> 4 <img src="${product.featured_image||product.images[0]}" alt="${product.title}" loading="lazy"> 5 </a> 6 </div> 7 <div class="drawer__recently-viewed-product-info"> 8 <h3 class="h3 drawer__recently-viewed-product-title"> 9 <a href="/products/${product.handle}">${product.title}</a> 10 </h3> 11 ${isOptical?"":`<div class="drawer__recently-viewed-product-price price${product.compare_at_price>product.price?" price--on-sale":""}"> 12 ${product.compare_at_price>product.price?`<span class="price__original" aria-hidden="true"> 13 ${this.formatMoney(product.compare_at_price)} 14 </span>
15 <span class="visually-hidden">Regular price</span>`:""} 16 <span class="price__current"> 17 ${this.formatMoney(product.price)} 18 </span> 19 ${product.compare_at_price>product.price?`<span class="visually-hidden">Sale price</span> 20 <span class="price__savings"> 21 Save ${this.formatMoney(product.compare_at_price-product.price)} 22 </span>`:""} 23 </div>`} 24 </div> 25 ${isOptical?"":product.tags&&product.tags.includes("coming-soon")?`<a href="/products/${product.handle}" class="button button--secondary drawer__recently-viewed-product-sold-out"> 26 Coming soon 27 </a>`:product.available&&product.variants&&product.variants.length===1?`<button 28 class="button button--secondary drawer__recently-viewed-product-add${isInCart?" added":""}" 29 data-quick-add 30 data-product-id="${product.id}" 31 data-variant-id="${product.variants[0].id}" 32 ${isInCart?"disabled":""} 33 > 34 <svg class="icon icon-plus" xmlns="http://www.w3.org/2000/svg" width="16" height="19" viewBox="0 0 16 19" fill="none"> 35 <path class="icon-plus__horizontal" d="M7.42746 8.55261H1.14174H0.570312V9.69296H1.
3514174H7.42746H8.57031H14.856H15.4275V8.55261H14.856H8.57031H7.42746Z" fill="inherit"/> 36 <path class="icon-plus__vertical" d="M8.57031 8.55136L8.57031 2.26564L8.57031 1.69421L7.42996 1.69421L7.42996 2.26564L7.42996 8.55136L7.42996 9.69421L7.42996 15.9799L7.42996 16.5514L8.57031 16.5514L8.57031 15.9799L8.57031 9.69421L8.57031 8.55136Z" fill="inherit"/> 37 </svg> 38 <span class="button__text"> 39 Add 40 </span> 41 <span class="button__text--added"> 42 Added 43 </span> 44 </button>`:product.available?`<a href="/products/${product.handle}" class="button button--secondary"> 45 View 46 </a>`:`<a href="/products/${product.handle}" class="button button--secondary drawer__recently-viewed-product-sold-out"> 47 Notify me 48 </a>`} 49 `,container.appendChild(productEl)}),setTimeout(()=>{typeof window.initQuickAddButtons=="function"?window.initQuickAddButtons(container):this.initQuickAddButtons(container)},100)):container.innerHTML='<p class="empty-state">No recently viewed products</p>'})}catch(error){console.error("Error loading recently viewed products:",error),container.innerHTML='<p class="empty-state">Unable to load recently viewed products</p>'}}initQuickAddButtons(container){container.querySelectorAll("[data-quick-add][data-quick-add-initialized]").forEach(button=>{button.removeAttribute("data-quick-add-initialized")}),typeof window.initQuickAddButtons=="function"&&window.initQuickAddButtons(container)}switchToCartTab(){const cartTab=this.querySelector(".drawer__tab--cart"),cartContent=this.querySelector(".drawer__tab-content--cart");if(cartTab&&cartContent){const allTabs=this.querySelectorAll(".drawer__tab"),allContent=this.querySelectorAll(".drawer__tab-content");allTabs.forEach(t=>t.classList.remove("active")),allContent.forEach(c=>c.classList.remove("active")),cartTab.classList.add("active"),cartContent.classList.add("active"),this.shouldSwitchToCartTab=!1}else console.warn("Could not find cart tab elements")}updateRecentlyViewedButtonStates(){this.querySelectorAll(".drawer__recently-viewed-product-add").forEach(button=>{const variantId=button.getAttribute("data-variant-id"),isInCart=this.isVariantInCart(variantId);isInCart&&!button.classList.contains("added")?(button.classList.add("added"),button.disabled=!0):!isInCart&&button.classList.contains("added")&&(button.classList.remove("added"),button.disabled=!1)})}formatMoney(cents){return"\u20AC"+(parseFloat(cents)/100).toFixed(2)}setHeaderCartIconAccessibility(){const cartLink=document.querySelector("#cart-icon-bubble");cartLink&&(cartLink.setAttribute("role","button"),cartLink.setAttribute("aria-haspopup","dialog"),cartLink.addEventListener("click",event=>{event.preventDefault(),this.open(cartLink)}),cartLink.addEventListener("keydown",event=>{event.code.toUpperCase()==="SPACE"&&(event.preventDefault(),this.open(cartLink))}))}open(triggeredBy){triggeredBy&&this.setActiveElement(triggeredBy);const cartDrawerNote=this.querySelector('[id^="Details-"] summary');cartDrawerNote&&!cartDrawerNote.hasAttribute("role")&&this.setSummaryAccessibility(cartDrawerNote),this.checkRecentlyViewedProducts(),setTimeout(()=>{this.classList.add("animate","active")}),this.addEventListener("transitionend",()=>{const containerToTrapFocusOn=this.classList.contains("is-empty")?this.querySelector(".drawer__inner-empty"):document.getElementById("CartDrawer"),focusElement=this.querySelector(".drawer__inner")||this.querySelector(".drawer__close")},{once:!0}),document.querySelector("body")?.classList.remove("overlay-open--left"),document.querySelector("body")?.classList.remove("search-modal-open"),document.querySelector("body")?.classList.remove("modal-open"),document.querySelector("#search-modal")?.setAttribute("aria-hidden","true"),document.body.classList.add("overflow-hidden"),document.body.classList.add("overlay-open")}close(){this.classList.remove("active"),removeTrapFocus(this.activeElement),document.body.classList.remove("overflow-hidden"),document.body.classList.remove("overlay-open")}setSummaryAccessibility(cartDrawerNote){cartDrawerNote.setAttribute("role","button"),cartDrawerNote.setAttribute("aria-expanded","fal
49se"),cartDrawerNote.nextElementSibling.getAttribute("id")&&cartDrawerNote.setAttribute("aria-controls",cartDrawerNote.nextElementSibling.id),cartDrawerNote.addEventListener("click",event=>{event.currentTarget.setAttribute("aria-expanded",!event.currentTarget.closest("details").hasAttribute("open"))}),cartDrawerNote.parentElement.addEventListener("keyup",onKeyUpEscape)}renderContents(parsedState){const recentlyViewedState=this.saveRecentlyViewedState();this.querySelector(".drawer__inner").classList.contains("is-empty")&&this.querySelector(".drawer__inner").classList.remove("is-empty"),this.productId=parsedState.id,this.getSectionsToRender().forEach(section=>{const sectionElement=section.selector?document.querySelector(section.selector):document.getElementById(section.id);sectionElement&&(sectionElement.innerHTML=this.getSectionInnerHTML(parsedState.sections[section.id],section.selector))}),setTimeout(()=>{this.initCartDrawerAfterUpdate(recentlyViewedState),this.open()})}getSectionInnerHTML(html,selector=".shopify-section"){return selector==".cart-wrapper__inner"&&!document.getElementById("CartMain")?"":new DOMParser().parseFromString(html,"text/html").querySelector(selector).innerHTML}getSectionsToRender(){return[{id:"CartDrawer",section:"cart-drawer",selector:".drawer__inner"},{id:"CartMain",section:"cart",selector:".cart-wrapper__inner"}]}setActiveElement(element){this.activeElement=element}}customElements.define("cart-drawer",CartDrawer);class CartDrawerItems extends CartItems{getSectionsToRender(){return[{id:"CartDrawer",section:"cart-drawer",selector:".drawer__inner"},{id:"CartMain",section:"cart",selector:".cart-wrapper__inner"}]}}customElements.define("cart-drawer-items",CartDrawerItems),window.refreshCart=function(showDrawer=!0){const isCartPage=window.location.pathname.includes("/cart")||document.querySelector(".cart-wrapper")!==null,cartDrawer=document.querySelector("cart-drawer");let recentlyViewedState=null;cartDrawer&&(recentlyViewedState=cartDrawer.saveRecentlyViewedState()),fetch("/cart.js").then(response=>response.json()).then(cartData=>{const updatePromises=[];if(cartDrawer){const drawerPromise=fetch(`${routes.cart_url}?section_id=cart-drawer`).then(response=>response.text()).then(responseText=>{const html=new DOMParser().parseFromString(responseText,"text/html"),wasEmpty=cartDrawer.classList.contains("is-empty"),nowEmpty=cartData.item_count===0;if(wasEmpty&&!nowEmpty){const drawerInner=cartDrawer.querySelector(".drawer__inner"),newDrawerInner=html.querySelector(".drawer__inner");drawerInner&&newDrawerInner&&(drawerInner.innerHTML=newDrawerInner.innerHTML,cartDrawer.classList.remove("is-empty"),cartDrawer.initCartDrawerAfterUpdate(recentlyViewedState))}else{const cartItemsWrapper=cartDrawer.querySelector(".drawer__cart-items-wrapper"),newCartItemsWrapper=html.querySelector(".drawer__cart-items-wrapper");cartItemsWrapper&&newCartItemsWrapper&&(cartItemsWrapper.innerHTML=newCartItemsWrapper.innerHTML);const subtotal=cartDrawer.querySelector("#cart-drawer-subtotal"),newSubtotal=html.querySelector("#cart-drawer-subtotal");subtotal&&newSubtotal&&(subtotal.textContent=newSubtotal.textContent);const drawerInner=cartDrawer.querySelector(".drawer__inner");drawerInner&&(drawerInner.classList.toggle("is-empty",cartData.item_count===0),cartDrawer.classList.toggle("is-empty",cartData.item_count===0));const cartTab=cartDrawer.querySelector(".drawer__tab--cart");if(cartTab){let countElement=cartTab.querySelector("#cart-drawer-item-count");if(cartData.item_count>0)if(countElement)countElement.textContent=cartData.item_count;else{const headingElement=cartTab.querySelector("#cart-drawer-heading");headingElement?headingElement.insertAdjacentHTML("afterend",`<span class="drawer__heading--item-count" id="cart-drawer-item-count">${cartData.item_count}</span>`):cartTab.insertAdjacentHTML("beforeend",`<span class="drawer__heading--item-count" id="cart-drawer-item-count">${cartData.item_count}</span>`)}else countElement&&countElement.remove()}recentlyViewedState&&setTimeout(()=>{if(cartDrawer.restoreRecentlyViewedState(recentlyViewedState),cartDrawer){const container=cartDrawer.querySelector(".drawer__recently-viewed-products-wrapper");container&&setTimeout(()=>{cartDrawer.initQuickAddButtons(container),cartDrawer.shouldSwitchToCartTab&&(cartDrawer.switchToCartTab(),cartDrawer.shouldSwitchToCartTab=!1)},100)}},0)}if(cartDrawer&&(cartDrawer.shouldSwitchToCartTab&&setTimeout(()=>{cartDrawer.switchToCartTab()},100),cartDrawer.querySelector(".drawer__tab--recently-viewed.active"))){const container=cartDrawer.querySelector(".drawer__recently-viewed-products-wrapper");container&&setTimeout(()=>cartDrawer.initQuickAddButtons(container),100)}if(cartDrawer){const container=cartDrawer.querySelector(".drawer__recently-viewed-products-wrapper");container&&setTimeout(()=>{typeof window.initQuickAddButtons=="function"&&window.initQuickAddButtons(container)},200)}showDrawer&&!(isCartPage&&document.activeElement?.hasAttribute("data-quick-add"))&&setTimeout(()=>cartDrawer.open(),10)});updatePromises.push(drawerPromise)}if(isCartPage){const cartPagePromise=fetch(window.location.href).then(response=>response.text()).then(responseText=>{const html=new DOMParser().parseFromString(responseText,"text/html"),mainCartItems=document.getElementById("main-cart-items");if(mainCartItems){const sourceItems=html.querySelector("#main-cart-items");sourceItems&&(mainCartItems.innerHTML=sourceItems.innerHTML)}const cartSummary=document.querySelector(".cart__summary");if(cartSummary){const sourceSummary=html.querySelector(".cart__summary");sourceSummary&&(cartSummary.innerHTML=sourceSummary.innerHTML)}});updatePromises.push(cartPagePromise)}Promise.all(updatePromises).then(()=>{isCartPage&&document.querySelectorAll("quantity-input").forEach(input=>{typeof input.validateQtyRules=="function"&&input.validateQtyRules()}),updateCartCounters(cartData.item_count),publish(PUB_SUB_EVENTS.cartUpdate,{source:"refresh-cart",cartData})}).catch(error=>{console.error("Error updating cart:",error),publish(PUB_SUB_EVENTS.cartUpdate,{source:"refresh-cart",cartData})})}).catch(error=>{console.error("Error fetching cart data:",error)})},window.openCart=function(){const cartDrawer=document.querySelector("cart-drawer");cartDrawer&&(document.querySelector(".header-sidebar-nav")?.classList.remove("active"),document.querySelector(".header__menu-mobile-toggle")?.classList.remove("header__menu-mobile-toggle--open"),document.querySelector("body").classList.remove("overlay-open--left"),document.querySelector("body").classList.remove("search-modal-open"),document.querySelector("body").classList.remove("modal-open"),document.querySelector("#search-modal")?.setAttribute("aria-hidden","true"),cartDrawer.open())},window.closeCart=function(){const cartDrawer=document.querySelector("cart-drawer");cartDrawer&&cartDrawer.close()},document.addEventListener("DOMContentLoaded",()=>{subscribe(PUB_SUB_EVENTS.cartUpdate,event=>{if(event.cartData){const cartDrawer=document.querySelector("cart-drawer");updateRelatedProductButtonState(event.cartData),updateCartCounters(event.cartData.item_count);const cartPage=document.querySelector(".cart-wrapper")}}),fetch("/cart.js").then(response=>response.json()).then(cartData=>{updateRelatedProductButtonState(cartData),updateCartCounters(cartData.item_count)}
49).catch(error=>{console.error("Error fetching initial cart data for related product:",error)})});function updateRelatedProductButtonState(cartData){if(!window.location.pathname.includes("/products/"))return;const relatedProductButton=document.querySelector(".related-product .button");if(!relatedProductButton)return;const variantId=relatedProductButton.getAttribute("data-variant-id");if(!variantId)return;const isInCart=cartData?.items?.some(item=>item.variant_id.toString()===variantId);if(isInCart&&!relatedProductButton.classList.contains("added")){relatedProductButton.classList.add("added"),relatedProductButton.disabled=!0;const buttonText=relatedProductButton.querySelector(".button__text");buttonText&&(buttonText.textContent="Added")}else if(!isInCart&&relatedProductButton.classList.contains("added")){relatedProductButton.classList.remove("added"),relatedProductButton.disabled=!1;const buttonText=relatedProductButton.querySelector(".button__text");buttonText&&(buttonText.textContent="Add to cart")}}class CartUpsell{constructor(options){this.options={container:"#cart-drawer-upsell",freeShippingThreshold:6e3,watchStrapCollection:"straps",eyewearCordsCollection:"cords",...options},this.container=document.querySelector(this.options.container),this.initialized=!1,this.container&&(this.cartUpdateListener=subscribe(PUB_SUB_EVENTS.cartUpdate,this.updateUpsell.bind(this)),this.loadCollections())}async loadCollections(){try{const[strapsResponse,cordsResponse]=await Promise.all([fetch(`/collections/${this.options.watchStrapCollection}/products.json?limit=50`),fetch(`/collections/${this.options.eyewearCordsCollection}/products.json?limit=50`)]),strapsData=await strapsResponse.json();this.watchStraps=strapsData.products.filter(p=>p.variants.some(variant=>variant.available));const cordsData=await cordsResponse.json();this.eyewearCords=cordsData.products.filter(p=>p.variants.some(variant=>variant.available)),this.initialized=!0,this.updateUpsell()}catch(error){console.error("Error loading upsell collections:",error)}}async updateUpsell(event){if(this.initialized)try{const cart=await(await fetch("/cart.js")).json(),amountToFreeShipping=this.options.freeShippingThreshold-cart.total_price;if(amountToFreeShipping<=0){this.hideUpsell();return}const upsellProduct=this.findUpsellProduct(cart,amountToFreeShipping);upsellProduct?this.renderUpsell(upsellProduct,amountToFreeShipping):this.hideUpsell()}catch(error){console.error("Error updating upsell:",error),this.hideUpsell()}}findUpsellProduct(cart,amountToFreeShipping){const hasWatch=cart.items.some(item=>item.product_type?.toLowerCase()==="watch"||item.product_type?.toLowerCase().includes("watch")),hasSunglasses=cart.items.some(item=>item.product_type?.toLowerCase()==="sunglasses"||item.product_type?.toLowerCase().includes("eyewear"));let potentialUpsells=[];hasWatch&&this.watchStraps?.length?potentialUpsells=[...this.watchStraps]:hasSunglasses&&this.eyewearCords?.length&&(potentialUpsells=[...this.eyewearCords]);const cartVariantIds=cart.items.map(item=>item.variant_id);return potentialUpsells.filter(product=>{const price=parseInt(product.variants[0].price),wouldQualify=price>0&&price<=amountToFreeShipping+1e3,isInCart=product.variants.some(variant=>cartVariantIds.includes(variant.id));return wouldQualify&&!isInCart}).sort((a,b)=>b.variants[0].price-a.variants[0].price)[0]}renderUpsell(product,amountToFreeShipping){if(this.container=document.querySelector("#cart-drawer-upsell"),!this.container)return;const remainingAmount=(amountToFreeShipping/100).toFixed(2),titleElement=this.container.querySelector(".cart-drawer__upsell-title");titleElement&&(titleElement.textContent="Complete your look and get free shipping from \u20AC120.00");const contentElement=this.container.querySelector(".cart-drawer__upsell-content");if(contentElement){const variant=product.variants[0],price=parseInt(variant.price).toFixed(2),shippingThreshold=(this.options.freeShippingThreshold/100).toFixed(2);contentElement.innerHTML=` 50 <div class="related-product__content"> 51 <a class="related-product__image-container" href="/products/${product.handle}"> 52 <img src="${product.featured_image?.src||product.images[0]?.src}" 53 alt="${product.title}" 54 class="related-product__image" 55 loading="lazy"> 56 </a> 57 58 <div class="related-product__details"> 59 <h4 class="related-product__details--title">Complete your look and get free shipping from \u20AC${shippingThreshold}</h4> 60 <div class="related-product__details--info"> 61 <div class="related-product__details--title-wrapper"> 62 <h4 class="related-product__product-title">${product.title}</h4> 63 <p class="related-product__price">\u20AC${price}</p> 64 </div> 65 <button 66 class="button button--secondary button--small" 67 data-variant-id="${variant.id}" 68 data-product-id="${product.id}" 69 onclick="quickAdd('${variant.id}', this)"> 70 <svg class="icon icon-plus" xmlns="http://www.w3.org/2000/svg" width="16" height="19" viewBox="0 0 16 19" fill="none"> 71 <path class="icon-plus__horizontal" d="M7.42746 8.55261H1.14174H0.570312V9.69296H1.
7114174H7.42746H8.57031H14.856H15.4275V8.55261H14.856H8.57031H7.42746Z" fill="inherit"></path> 72 <path class="icon-plus__vertical" d="M8.57031 8.55136L8.57031 2.26564L8.57031 1.69421L7.42996 1.69421L7.42996 2.26564L7.42996 8.55136L7.42996 9.69421L7.42996 15.9799L7.42996 16.5514L8.57031 16.5514L8.57031 15.9799L8.57031 9.69421L8.57031 8.55136Z" fill="inherit"></path> 73 </svg> 74 <span class="related-product__button-add">Add</span> 75 </button> 76 </div> 77 </div> 78 </div> 79 `}this.container.classList.add("is-loaded")}hideUpsell(){this.container&&this.container.classList.remove("is-loaded")}}document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll("[data-quick-add]").forEach(button=>{const productId=button.getAttribute("data-product-id"),variantId=button.getAttribute("data-variant-id");if(productId&&variantId){let productHandle=button.closest("[data-product-handle]")?.getAttribute("data-product-handle");productHandle&&checkProductAvailability(productHandle,variantId)}});const productForm=document.querySelector("form.shopify-product-form");if(productForm){const variantId=productForm.querySelector('[name="id"]')?.value,productHandle=document.querySelector(".product")?.getAttribute("data-product-handle")||window.location.pathname.split("/products/")[1]?.split("?")[0];variantId&&productHandle&&checkProductAvailability(productHandle,variantId)}typeof window.cartUpsellEnabled<"u"&&window.cartUpsellEnabled&&(window.cartUpsell=new CartUpsell({freeShippingThreshold:6e3,watchStrapCollection:"straps",eyewearCordsCollection:"cords"}))}); 80//# sourceMappingURL=/cdn/shop/t/217/assets/cart.js.map?v=181797535892162594661783522154
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.