document.addEventListener("DOMContentLoaded",function(){const e=document.querySelectorAll(".zolo-contact-form");e.length>0&&e.forEach(e=>{if("true"==e.dataset.recaptcha)return;const t=(e,o=10)=>{e.querySelector(".zolo-form-date-picker")||0===o?function(e){const t=e.dataset.formId;let o=e.parentNode.querySelector(".zolo-form-msg"),s=e.parentNode.querySelector(".zolo-msg-desc");const r=e.parentNode.querySelector(".zolo-msg-close");let n=new Pristine(e);const a=e.querySelectorAll("input.invalid-number, input.invalid-country");a.length>0&&a.forEach(e=>{const t=e.getAttribute("data-pristine-required-message")||"This field is required.";n.addValidator(e,function(t){return!e.classList.contains("invalid-number")&&""!==t.trim()},t)}),e.addEventListener("submit",function(a){a.preventDefault();const i=e.querySelector(".zolo-submit-btn button");let c=n.validate();const l=e=>e.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());if(c){const n=[...new FormData(e).entries()];n.push(["formId",t]),n.push(["nonce",zoloSettings.zolo_nonce]);const a=n.reduce((e,[t,o])=>("file"===t&&(o=o?.name),e[t]?e[t]=`${l(e[t])}, ${l(o)}`:e[t]=o,e),{});n.forEach(([t,o])=>{e.querySelectorAll(`[name="${t}"]`).forEach(e=>{const o=e.closest("[data-field-settings]");if(o){const e=JSON.parse(o.dataset.fieldSettings);a[t]?.value||(a[t]={value:a[t],...e})}})});const c=JSON.stringify(a);i.disabled=!0,i.classList.add("loading"),fetch(zoloSettings.ajaxurl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"zolo_send_form_data",formData:c})}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(t=>{const{data:n,success:a}=t;i.disabled=!1,i.classList.remove("loading"),a?(s.innerHTML=n,o.classList.add("zolo-form-success-msg","show")):(s.innerHTML=n,o.classList.add("zolo-form-error-msg","show")),e.reset();const c=setTimeout(()=>{s.innerHTML="",o.classList.remove("validation-error","success","fail","show")},5e3);r.addEventListener("click",function(){clearTimeout(c),s.innerHTML="",o.classList.remove("validation-error","success","fail","show")})}).catch(e=>{console.error("Error:",e)}).finally(()=>{i.disabled=!1,i.classList.remove("loading")})}})}(e):setTimeout(()=>{t(e,o-1)},10)};t(e)})});