!function(){"use strict";const t=window.puffergoContactForm&&window.puffergoContactForm.endpoint?window.puffergoContactForm.endpoint:"/wp-json/puffergo/v1/contact";function e(t,e,n){let o=function(t){const e=t.querySelector("[data-pg-form-status]");if(e)return e;const n=t.nextElementSibling;return n&&null!==n.getAttribute("data-pg-form-status")?n:null}(t);o||(o=document.createElement("div"),o.setAttribute("data-pg-form-status",""),o.setAttribute("role","status"),t.parentNode.insertBefore(o,t.nextSibling)),o.textContent=n||"",o.className="pg-form-status pg-form-status--"+e}function n(t,e){t.querySelectorAll('button[type="submit"], input[type="submit"]').forEach(function(t){t.disabled=!!e})}document.addEventListener("submit",function(o){const r=o.target;if(!r||"contact"!==r.getAttribute("data-pg-submit"))return;if(o.preventDefault(),"true"===r.getAttribute("data-pg-submitting"))return;r.setAttribute("data-pg-submitting","true"),n(r,!0);const u=r.getAttribute("data-pg-loading-text")||"",i=r.getAttribute("data-pg-success-text")||"",s=r.getAttribute("data-pg-error-text")||"";e(r,"loading",u||"…");const a=function(t){const e=new FormData(t),n={};e.forEach(function(t,e){n[e]?(Array.isArray(n[e])||(n[e]=[n[e]]),n[e].push(t)):n[e]=t}),n.page_url=window.location.href;const o=document.querySelector("[data-pg-product-name]");return o&&o.value&&(n.product_name=o.value),n}(r);fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}).then(function(t){return t.json().then(function(e){return{ok:t.ok,data:e}})}).then(function(t){const n=t.ok,o=t.data;if(n&&o&&o.success){const t=r.getAttribute("data-pg-success-url");if(t)return void(window.location.href=t);e(r,"success",i||o.message||window.puffergoContactForm.i18n.submitSuccess||"Submitted successfully"),r.reset()}else e(r,"error",s||(o&&o.message?o.message:window.puffergoContactForm.i18n.submitFailed||"Submission failed"))}).catch(function(){e(r,"error",s||window.puffergoContactForm.i18n.submitFailed||"Submission failed")}).finally(function(){r.removeAttribute("data-pg-submitting"),n(r,!1)})})}();