class 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)})}}customElements.define("cart-remove-button",CartRemoveButton);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.id=="cart-items"&&document.querySelector("cart-drawer-items")||(this.cartUpdateUnsubscriber=subscribe(PUB_SUB_EVENTS.cartUpdate,event=>{event.source!=="cart-items"&&this.onCartUpdate()}))}disconnectedCallback(){this.cartUpdateUnsubscriber&&this.cartUpdateUnsubscriber()}resetQuantityInput(id){const input=this.querySelector(`#Quantity-${id}`);input&&(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;let message="";event.target.id.includes("quickadd")||(inputValueparseInt(event.target.max)?message=window.quickOrderListStrings.max_error.replace("[max]",event.target.max):inputValue%parseInt(event.target.step)!==0&&(message=window.quickOrderListStrings.step_error.replace("[step]",event.target.step)),message?this.setValidity(event,index,message):(event.target.setCustomValidity(""),event.target.reportValidity(),this.updateQuantity(index,inputValue,document.activeElement.getAttribute("name"),event.target.dataset.quantityVariantId)))}onChange(event){this.validateQuantity(event)}onCartUpdate(){document.querySelector("#CartDrawer")&&fetch(`${routes.cart_url}?section_id=cart-drawer`).then(response=>response.text()).then(responseText=>{const html=new DOMParser().parseFromString(responseText,"text/html"),selectors=[".drawer__inner"];for(const selector of selectors){const originalDiscountDetails=document.querySelector("cart-drawer .cart-discount details"),targetElement=document.querySelector(selector),sourceElement=html.querySelector(selector);targetElement&&sourceElement&&(targetElement.replaceWith(sourceElement),requestAnimationFrame(()=>{const discountDetails=document.querySelector("cart-drawer .cart-discount details");discountDetails&&(originalDiscountDetails&&originalDiscountDetails.hasAttribute("open")&&discountDetails.setAttribute("open",!0),discountDetails.classList.contains("loaded")||closingAccordions("cart-drawer .cart-discount details"))}))}}).catch(e=>{console.error(e)}),document.getElementById("cart-items")&&fetch(`${routes.cart_url}?section_id=${document.getElementById("cart-items")?.dataset.id}`).then(response=>response.text()).then(responseText=>{const sourceQty=new DOMParser().parseFromString(responseText,"text/html").querySelector("cart-items");document.getElementById("cart-items").innerHTML=sourceQty.innerHTML,document.getElementById("cart-items").classList=sourceQty.classList}).catch(e=>{console.error(e)}),document.getElementById("main-cart-footer")&&fetch(`${routes.cart_url}?section_id=${document.getElementById("main-cart-footer")?.dataset.id}`).then(response=>response.text()).then(responseText=>{const html=new DOMParser().parseFromString(responseText,"text/html"),originalDiscountDetails=document.querySelector("#main-cart-footer .cart-discount details"),sourceQty=html.querySelector("#main-cart-footer");document.getElementById("main-cart-footer").innerHTML=sourceQty.innerHTML,document.getElementById("main-cart-footer").classList=sourceQty.classList,requestAnimationFrame(()=>{const discountDetails=document.querySelector("#main-cart-footer .cart-discount details");discountDetails&&(originalDiscountDetails&&originalDiscountDetails.hasAttribute("open")&&discountDetails.setAttribute("open",!0),discountDetails.classList.contains("loaded")||closingAccordions("#main-cart-footer .cart-discount details"))})}).catch(e=>{console.error(e)}),document.getElementById("cart-featured-collection")&&fetch(`${routes.cart_url}?section_id=${document.querySelector("#cart-featured-collection").dataset.id}`).then(response=>response.text()).then(responseText=>{const sourceQty=new DOMParser().parseFromString(responseText,"text/html").querySelector("#cart-featured-collection");document.querySelector("#cart-featured-collection").innerHTML=sourceQty.innerHTML}).catch(e=>{console.error(e)}),document.getElementById("cart-navigation")&&fetch(`${routes.cart_url}?section_id=${document.querySelector("#cart-navigation").dataset.id}`).then(response=>response.text()).then(responseText=>{const sourceQty=new DOMParser().parseFromString(responseText,"text/html").querySelector("#CartNavigation-cart-item");document.querySelector("#CartNavigation-cart-item").innerHTML=sourceQty.innerHTML}).catch(e=>{console.error(e)})}getSectionsToRender(){const sectionsToRender=[];return document.getElementById("cart-items")&§ionsToRender.push({id:`shopify-section-${document.getElementById("cart-items")?.dataset.id}`,section:document.getElementById("cart-items")?.dataset.id,selector:"#cart-items"}),document.getElementById("cart-icon-bubble")&§ionsToRender.push({id:"cart-icon-bubble",section:"cart-icon-bubble",selector:".shopify-section"}),document.getElementById("main-cart-footer")&§ionsToRender.push({id:`shopify-section-${document.getElementById("main-cart-footer")?.dataset.id}`,section:document.getElementById("main-cart-footer")?.dataset.id,selector:"#main-cart-footer"}),document.getElementById("CartDrawer")&§ionsToRender.push({id:"CartDrawer",section:"cart-drawer",selector:".drawer__inner"}),document.getElementById("cart-navigation")&§ionsToRender.push({id:"cart-navigation",section:document.getElementById("cart-navigation")?.dataset.id,selector:"#CartNavigation-cart-item"}),document.getElementById("cart-featured-collection")&§ionsToRender.push({id:"cart-featured-collection",section:document.getElementById("cart-featured-collection")?.dataset.id,selector:"#cart-featured-collection"}),sectionsToRender}updateQuantity(line,quantity,name2,variantId){this.enableLoading(line);let parsedState;const body=JSON.stringify({line,quantity,sections_url:routes.cart_url});fetch(`${routes.cart_change_url}`,{...fetchConfig(),body}).then(response=>response.text()).then(state=>{parsedState=JSON.parse(state),publish(PUB_SUB_EVENTS.cartUpdate,{source:"cart-items",cartData:parsedState,variantId})}).catch(error=>{console.error(error),this.querySelectorAll(".loading__spinner").forEach(overlay=>overlay.classList.add("hidden"));const errors=document.getElementById("cart-errors")||document.getElementById("CartDrawer-CartErrors");errors.textContent=window.cartStrings.error}).finally(()=>{const items=document.querySelectorAll(".cart-item");this.renderSections(line,parsedState,items)})}renderSections(line,parsedState,items){fetch(`${routes.cart_url}`).then(response=>response.text()).then(responseText=>{const responseHTML=new DOMParser().parseFromString(responseText,"text/html");this.getSectionsToRender().forEach(section=>{const elementToReplace=document.getElementById(section.id).querySelector(section.selector)||document.getElementById(section.id);if(!elementToReplace)return;const elementReplacement=responseHTML.getElementById(section.id).querySelector(section.selector)||responseHTML.getElementById(section.id);elementToReplace.innerHTML=elementReplacement.innerHTML,section.id!="cart-icon-bubble"&&(elementToReplace.classList=elementReplacement.classList)}),this.classList.toggle("is-empty",parsedState.item_count===0);const cartDrawerWrapper=document.querySelector("cart-drawer"),cartFooter=document.getElementById("main-cart-footer");if(cartFooter&&cartFooter.classList.toggle("is-empty",parsedState.item_count===0),cartDrawerWrapper&&cartDrawerWrapper.classList.toggle("is-empty",parsedState.item_count===0),parsedState.errors){this.updateLiveRegions(line,parsedState.errors),this.disableLoading(line);return}const updatedValue=parsedState.items[line-1]?parsedState.items[line-1].quantity:void 0;let message="";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}"]`)||(parsedState.item_count===0&&cartDrawerWrapper?!cartDrawerWrapper.querySelector(".drawer__inner-empty")||cartDrawerWrapper.querySelector("a"):document.querySelector(".cart-item")&&cartDrawerWrapper&&trapFocus(cartDrawerWrapper,document.querySelector(".cart-item__name")))}).catch(e=>{console.error(e)})}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),(document.getElementById("cart-live-region-text")||document.getElementById("CartDrawer-LiveRegionText")).setAttribute("aria-hidden",!1)}getSectionInnerHTML(html,selector){return new DOMParser().parseFromString(html,"text/html").querySelector(selector).innerHTML}getSectionElement(html,selector){return new DOMParser().parseFromString(html,"text/html").querySelector(selector)}enableLoading(line){(document.getElementById("main-cart-items")||document.getElementById("CartDrawer-CartItems")).classList.add("cart__items--disabled");const cartItemElements=this.querySelectorAll(`#CartItem-${line} .loading__spinner`),cartDrawerItemElements=this.querySelectorAll(`#CartDrawer-Item-${line} .loading__spinner`);[...cartItemElements,...cartDrawerItemElements].forEach(overlay=>overlay.classList.remove("hidden")),document.activeElement.blur(),this.lineItemStatusElement.setAttribute("aria-hidden",!1)}disableLoading(line){(document.getElementById("main-cart-items")||document.getElementById("CartDrawer-CartItems")).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})},ON_CHANGE_DEBOUNCE_TIMER))}});
//# sourceMappingURL=/cdn/shop/t/365/assets/cart.js.map?v=6580078978018449961753250039