document.getElementById(`contactForm`).addEventListener(`submit`,async function(e){e.preventDefault();let t=new FormData(this),r=Object.fromEntries(t),i=n(r);if(Object.keys(i).length>0){a(i);return}let o=this.querySelector(`button[type="submit"]`),s=o.innerHTML;o.disabled=!0,o.innerHTML=`<i class="fas fa-spinner fa-spin"></i> Sending...`;try{let e=await(await fetch(`/api/contact`,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`,"X-CSRF-TOKEN":document.querySelector(`meta[name="csrf-token"]`).content,"X-Requested-With":`XMLHttpRequest`},body:new URLSearchParams(r)})).json();e.success?(showNotification(e.message,`success`),this.reset()):e.errors?a(e.errors):showNotification(e.message,`error`)}catch(e){console.error(`Error:`,e),showNotification(`An error occurred. Please try again or call us at 9879991799.`,`error`)}finally{o.disabled=!1,o.innerHTML=s}});function e(e){let t=String(e||``).replace(/[\s\-().]/g,``).replace(/^(\+91|91|0)/,``);return/^[6-9][0-9]{9}$/.test(t)}var t={name:e=>!e||e.trim().length<2?`Please enter your full name`:null,phone:t=>e(t)?null:`Please enter a valid 10-digit mobile number, e.g. 9876543210`,email:e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e||``)?null:`Please enter a valid email address`,service:e=>e?null:`Please select a service`,message:e=>!e||e.trim().length<10?`Please enter a message (minimum 10 characters)`:null,terms:e=>e?null:`Please agree to be contacted`};function n(e){let n={};return Object.keys(t).forEach(r=>{let i=t[r](e[r]);i&&(n[r]=i)}),n}function r(e,t){let n=e.closest(`.form-group`);if(!n)return;i(e),n.classList.add(`error`),e.setAttribute(`aria-invalid`,`true`);let r=document.createElement(`div`);r.className=`error-message`,r.setAttribute(`role`,`alert`),r.style.color=`#ef4444`,r.style.fontSize=`0.875rem`,r.style.marginTop=`0.25rem`,r.innerHTML=`<i class="fas fa-exclamation-circle"></i> ${t}`,e.parentNode.appendChild(r)}function i(e){let t=e.closest(`.form-group`);t&&(t.classList.remove(`error`),t.querySelectorAll(`.error-message`).forEach(e=>e.remove())),e.removeAttribute(`aria-invalid`)}function a(e){document.querySelectorAll(`.error-message`).forEach(e=>e.remove()),document.querySelectorAll(`.form-group.error`).forEach(e=>e.classList.remove(`error`)),document.querySelectorAll(`#contactForm [aria-invalid]`).forEach(e=>e.removeAttribute(`aria-invalid`)),Object.keys(e).forEach(t=>{let n=document.getElementById(t)||document.querySelector(`[name="${t}"]`);n&&r(n,e[t])});let t=document.querySelector(`.error-message`);t&&t.scrollIntoView({behavior:`smooth`,block:`center`}),showNotification(`Please correct the errors in the form`,`error`)}function o(e){return e.type===`checkbox`?e.checked?`on`:``:e.value}document.querySelectorAll(`#contactForm input, #contactForm select, #contactForm textarea`).forEach(e=>{let n=t[e.name];if(!n)return;e.addEventListener(`blur`,function(){let e=n(o(this));e?r(this,e):i(this)});let a=e.type===`checkbox`||e.tagName===`SELECT`?`change`:`input`;e.addEventListener(a,function(){i(this)})});