if(!customElements.get("product-form")){let validateForm2=function(form){const missingFields=[];return form&&form.querySelectorAll('[data-product-custom-field] [name][required]:not([hidden]):not([type="hidden"])').forEach(field=>{if(field.classList.remove("form-control--warning"),field.type==="radio"){const buttons=form.querySelectorAll(`input[name="${field.name}"]`);Array.from(buttons).some(btn=>btn.checked)||(missingFields.push(field),field.classList.add("form-control--warning"))}else field.value||(missingFields.push(field),field.classList.add("form-control--warning"))}),missingFields};var validateForm=validateForm2;customElements.define("product-form",class extends HTMLElement{constructor(){super(),this.selectors={form:"form",inputId:"[name=id]",submitButton:'[name="add"]',errorWrapper:".f-product-form__error-message-wrapper",customFields:["[data-product-custom-field]"]},this.domNodes=queryDomNodes(this.selectors,this),this.form=this.domNodes.form,this.submitButton=this.domNodes.submitButton,this.domNodes.inputId.disabled=!1,this.Notification=window.FoxTheme.Notification,this.notificationType=this.dataset.notificationType,this.customFields=document.querySelectorAll(this.selectors.customFields),this.form.addEventListener("submit",this.onSubmitHandler.bind(this))}onSubmitHandler(evt){evt.preventDefault();const missing=validateForm2(this.form.closest(".f-product-single__blocks"));if(missing?.length>0)return console.warn("Missing field(s): ",missing),this.Notification.show({target:this?.domNodes?.errorWrapper,method:"appendChild",type:"warning",message:window.FoxThemeStrings.requiredField});if(this.submitButton.classList.contains("btn--loading"))return;this.submitButton.setAttribute("aria-disabled",!0),this.submitButton.classList.add("btn--loading");const config={method:"POST",headers:{Accept:"application/javascript","X-Requested-With":"XMLHttpRequest"}},formData=new FormData(this.form);config.body=formData;const{FoxThemeSettings,FoxThemeStrings}=window;fetch(`${FoxThemeSettings.routes.cart_add_url}`,config).then(response=>response.json()).then(response=>{if(response.status)return this.Notification.show({target:this.notificationType==="toast"?document.body:this.domNodes.errorWrapper,method:"appendChild",type:"warning",message:response.description,last:3e3,sticky:this.notificationType==="toast"});(!FoxThemeSettings.cart.openDrawerWhenAdded||FoxThemeSettings.cart.cartType==="page")&&this.Notification.show({target:this.domNodes.errorWrapper,method:"appendChild",type:"success",message:FoxThemeStrings.item_added,last:3e3,sticky:this.notificationType==="toast"}),FoxThemeSettings.cart.cartType==="page"&&FoxThemeCartHelpers.getState().then(state=>{FoxThemeCartHelpers.updateCartCount(state.item_count)}),window.FoxThemeEvents.emit("ON_ITEM_ADDED",response)}).catch(e=>{console.error(e)}).finally(()=>{this.submitButton.classList.remove("btn--loading"),this.submitButton.removeAttribute("aria-disabled")})}})} //# sourceMappingURL=/cdn/shop/t/3/assets/product-form.js.map?v=147576727112933915621672340465