(()=>{"use strict";const t=window.wp.i18n,{grecaptcha:e,GHOSTKIT:{googleReCaptchaAPISiteKey:i,events:r}}=window,o=".ghostkit-form-field-name-first, .ghostkit-form-field-name-last, .ghostkit-form-field-email-primary, .ghostkit-form-field-email-confirm, .ghostkit-form-field";function s(t,e){const i=t.closest(o);if(!i)return;let r=i.querySelector(".ghostkit-form-field-error");r||(r=document.createElement("div"),r.classList.add("ghostkit-form-field-error"),i.append(r)),r.innerHTML=e,r.setAttribute("aria-hidden",!1),t.setAttribute("aria-invalid",!0)}r.on(document,"init.blocks.gkt",(()=>{document.querySelectorAll("form.ghostkit-form:not(.ghostkit-form-ready)").forEach((e=>{e.classList.add("ghostkit-form-ready"),e.setAttribute("novalidate",""),Array.from(e.elements).forEach((i=>{let o="";if("email"===i.type&&i.dataset.confirmEmail){const s=e.querySelector(i.dataset.confirmEmail);s&&(o=(0,t.__)("These emails should match.","ghostkit"),s.getAttribute("required")&&i.setAttribute("required",s.getAttribute("required")),r.on(s,"input",(()=>{s.value?(i.setAttribute("pattern",s.value),i.setAttribute("required",!0)):(i.removeAttribute("pattern",s.value),s.getAttribute("required")?i.setAttribute("required",s.getAttribute("required")):i.removeAttribute("required"))})))}r.on(i,"invalid",(()=>{o&&i.validity.patternMismatch?s(i,o):s(i,i.validationMessage)}))}))}))})),r.on(document,"submit",".ghostkit-form",(t=>{const r=t.delegateTarget;if(!r.checkValidity())return t.preventDefault(),r.classList.add("ghostkit-form-was-validated"),void r.querySelector(":invalid").focus();if(void 0!==e){if(r.classList.contains("ghostkit-form-processed"))return;const o=r.querySelector('[name="ghostkit_form_google_recaptcha"]');if(!o)return;if(t.preventDefault(),r.classList.contains("ghostkit-form-processing"))return;r.classList.add("ghostkit-form-processing"),e.ready((()=>{e.execute(i,{action:"ghostkit"}).then((t=>{o.value=t,r.classList.add("ghostkit-form-processed"),r.submit(),r.classList.remove("ghostkit-form-processing","ghostkit-form-processed")}))}))}})),r.on(document,"blur",".ghostkit-form-was-validated",(t=>{t.target.checkValidity()})),r.on(document,"input",".ghostkit-form",(t=>{const e=t.target;e.checkValidity()&&function(t){const e=t.closest(o).querySelector(".ghostkit-form-field-error");e&&(e.innerHTML="",e.setAttribute("aria-hidden",!0)),t.setAttribute("aria-invalid",!1)}(e)}))})();