if(!customElements.get("product-form")){class ProductForm extends HTMLElement{constructor(){super(),this.hasChildNodes()&&this.init()}init(){this.form=this.querySelector(".js-product-form"),this.form&&(this.form.querySelector('[name="id"]').disabled=!1,this.cartDrawer=document.querySelector("cart-drawer"),this.submitBtn=this.querySelector('[name="add"]'),theme.settings.afterAtc!=="no-js"&&this.form.addEventListener("submit",this.handleSubmit.bind(this)))}async handleSubmit(evt){if(evt.target.id==="product-signup_form"||(evt.preventDefault(),this.submitBtn.getAttribute("aria-disabled")==="true"))return;theme.settings.vibrateOnATC&&window.navigator.vibrate&&window.navigator.vibrate(100),this.errorMsg=null,this.setErrorMsgState(),this.submitBtn.setAttribute("aria-disabled","true"),this.submitBtn.classList.add("is-loading");const formData=new FormData(this.form);let sections="cart-icon-bubble";this.cartDrawer&&(sections+=`,${this.cartDrawer.closest(".shopify-section").id.replace("shopify-section-","")}`),formData.append("sections_url",window.location.pathname),formData.append("sections",sections);const fetchRequestOpts={method:"POST",headers:{Accept:"application/javascript","X-Requested-With":"XMLHttpRequest"},body:formData};try{const oldCartResponse=await fetch(`${theme.routes.cart}.js`);if(!oldCartResponse.ok)throw new Error(oldCartResponse.status);const oldCartData=await oldCartResponse.json(),response=await fetch(theme.routes.cartAdd,fetchRequestOpts),data=await response.json();let error=typeof data.description=="string"?data.description:data.message;if(data.errors&&typeof data.errors=="object"&&(error=Object.entries(data.errors).map(item=>item[1].join(", "))),data.status&&this.setErrorMsgState(error),!response.ok)throw new Error(response.status);if(theme.settings.afterAtc==="page")setTimeout(()=>{window.location.href=theme.routes.cart},300);else{ProductForm.updateCartIcon(data);const quickAddDrawer=this.closest("quick-add-drawer");quickAddDrawer&&quickAddDrawer.addedToCart(),setTimeout(()=>{if(this.cartDrawer)this.cartDrawer.renderContents(data,!quickAddDrawer&&theme.settings.afterAtc==="drawer");else if(window.location.pathname===theme.routes.cart){const cartItems=document.querySelector("cart-items");cartItems&&(cartItems.dataset.empty==="true"?window.location.reload():cartItems.refresh())}},700)}const newCartResponse=await fetch(`${theme.routes.cart}.js`);if(!newCartResponse.ok)throw new Error(newCartResponse.status);const newCartData=await newCartResponse.json(),itemInOldCart=oldCartData.items.filter(item=>item.variant_id===data.variant_id)[0];itemInOldCart?this.dispatchEvent(new CustomEvent("on:line-item:change",{bubbles:!0,detail:{cart:newCartData,variantId:data.variant_id,oldQuantity:itemInOldCart.quantity,newQuantity:itemInOldCart.quantity===data.quantity?itemInOldCart.quantity:data.quantity}})):this.dispatchEvent(new CustomEvent("on:cart:add",{bubbles:!0,detail:{cart:newCartData,variantId:data.variant_id}}))}catch(error){console.log(error),this.dispatchEvent(new CustomEvent("on:cart:error",{bubbles:!0,detail:{error:this.errorMsg.textContent}}))}finally{this.submitBtn.classList.add("is-success"),this.submitBtn.removeAttribute("aria-disabled"),setTimeout(()=>{this.submitBtn.classList.remove("is-loading"),this.submitBtn.classList.remove("is-success")},1400)}}static updateCartIcon(response){const cartIconBubble=document.getElementById("cart-icon-bubble");cartIconBubble&&(cartIconBubble.innerHTML=response.sections["cart-icon-bubble"])}setErrorMsgState(error=!1){this.errorMsg=this.errorMsg||this.querySelector(".js-form-error"),this.errorMsg&&(this.errorMsg.hidden=!error,error&&(this.errorMsg.innerHTML="",(Array.isArray(error)?error:[error]).forEach((err,index)=>{index>0&&this.errorMsg.insertAdjacentHTML("beforeend","
"),this.errorMsg.insertAdjacentText("beforeend",err)})))}}customElements.define("product-form",ProductForm)} //# sourceMappingURL=/cdn/shop/t/10/assets/product-form.js.map?v=65023693641062547211716915740