(function(){"use strict";window.kadenceAdvancedForm={error_item:1,clearForm(a){a.reset()},insertAfter(a,b){b.parentNode.insertBefore(a,b.nextSibling)},markError(a,b,c){var d="";if(c.classList.contains("kb-adv-form-has-error")||c.classList.add("kb-adv-form-has-error"),a.classList.add("has-error"),b){switch(b){case"required":const c=a.getAttribute("data-kb-required-message");if(c&&""!==c){d=c;break}d=a.getAttribute("data-required-message"),d&&""!==d&&void 0!==d||(d=a.getAttribute("data-label"),(!d||""===d||void 0===d)&&(d=kb_adv_form_params.item),d=d+" "+kb_adv_form_params[b]);break;case"mismatch":d=a.getAttribute("data-mismatch-message"),d&&""!==d&&void 0!==d||(d=a.getAttribute("data-label"),(!d||""===d||void 0===d)&&(d=kb_adv_form_params.item),d=d+" "+kb_adv_form_params[b]);break;case"validation":d=a.getAttribute("data-validation-message"),d&&""!==d&&void 0!==d||(d=a.getAttribute("data-label"),(!d||""===d||void 0===d)&&(d=kb_adv_form_params.item),d=d+" "+kb_adv_form_params[b]);}var e=a.parentNode.querySelector(".kb-adv-form-error-msg");e&&e.remove();var f=a.getAttribute("name")+"-error";a.setAttribute("aria-describedby",f),a.setAttribute("aria-invalid","true");var g=document.createElement("div");g.id=f,g.classList.add("kb-adv-form-error-msg"),g.classList.add("kb-adv-form-message"),g.classList.add("kb-adv-form-warning"),g.setAttribute("role","alert"),g.innerHTML=d,a.classList.contains("kb-accept-field")?a.parentNode.parentNode.append(g):a.classList.contains("kb-checkbox-field")||a.classList.contains("kb-radio-field")?a.parentNode.append(g):window.kadenceAdvancedForm.insertAfter(g,a)}1===window.kadenceAdvancedForm.error_item&&a.focus(),window.kadenceAdvancedForm.error_item++},addErrorNotice(a){var b=a.getAttribute("data-error-message");b&&""!==b&&void 0!==b||(b=kb_adv_form_params.error_message);var c=document.createElement("div");c.classList.add("kb-adv-form-message"),c.classList.add("kb-adv-form-warning"),c.innerHTML=b,window.kadenceAdvancedForm.insertAfter(c,a)},isValidEmail(a){var b=new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);return b.test(a)},isValidURL(a){return /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([0-9A-Za-z]+.)/.test(a)},isValidTel(a){return /\/^[+]?[(]?[0-9]{3}[)]?[-s.]?[0-9]{3}[-s.]?[0-9]{4,6}$\/im/.test(a)},removeErrors(a){a.classList.contains("kb-adv-form-has-error")&&a.classList.remove("kb-adv-form-has-error");var b=a.querySelectorAll(".has-error");if(b.length)for(var c=0;c<b.length;c++){b[c].classList.remove("has-error"),b[c].removeAttribute("aria-describedby"),b[c].removeAttribute("aria-invalid");var d=b[c].parentNode.querySelector(".kb-adv-form-error-msg");d&&d.remove()}var e=document.querySelectorAll(".kb-adv-form-message");if(e.length)for(var c=0;c<e.length;c++)e[c].remove();var f=a.querySelectorAll(".kb-adv-form-errors");if(f.length)for(var c=0;c<f.length;c++)f[c].remove()},serialize(a){var b={};for(var[c,d]of a)void 0===b[c]?b[c]=d:(Array.isArray(b[c])||(b[c]=[b[c]]),b[c].push(d));return b},validateForm(a){var b=!1,c="";window.kadenceAdvancedForm.removeErrors(a);var d=a.querySelectorAll("[data-required=\"yes\"]:not([disabled])");if(d.length)for(var e=0;e<d.length;e++){var f=d[e].getAttribute("data-type"),g="";switch(f){case"textarea":case"text":g=d[e].value.trim(),""===g&&(b=!0,c="required",window.kadenceAdvancedForm.markError(d[e],c,a));break;case"tel":g=d[e].value.trim(),""!==g||""===g&&(b=!0,c="required",window.kadenceAdvancedForm.markError(d[e],c,a));break;case"accept":!1==d[e].checked&&(b=!0,c="required",window.kadenceAdvancedForm.markError(d[e],c,a));break;case"select":g=d[e].value,d[e].multiple?(null===g||0===g.length)&&(b=!0,c="required",window.kadenceAdvancedForm.markError(d[e],c,a)):(!g||"-1"===g)&&(b=!0,c="required",window.kadenceAdvancedForm.markError(d[e],c,a));break;case"radio":var h=d[e].querySelector("input:checked");h||(b=!0,c="required",window.kadenceAdvancedForm.markError(d[e],c,a));break;case"checkbox":var h=d[e].querySelector("input:checked");h||(b=!0,c="required",window.kadenceAdvancedForm.markError(d[e],c,a));break;case"email":var g=d[e].value.trim();""===g?""===g&&(b=!0,c="required",window.kadenceAdvancedForm.markError(d[e],c,a)):!window.kadenceAdvancedForm.isValidEmail(g)&&(b=!0,c="validation",window.kadenceAdvancedForm.markError(d[e],c,a));break;case"url":var g=d[e].value.trim();""===g?""===g&&(b=!0,c="required",window.kadenceAdvancedForm.markError(d[e],c,a)):!window.kadenceAdvancedForm.isValidURL(g)&&(b=!0,c="validation",window.kadenceAdvancedForm.markError(d[e],c,a));}}if(b)return window.kadenceAdvancedForm.addErrorNotice(a),!1;var i=new FormData(a);return i.set("_kb_form_verify",kb_adv_form_params.nonce),i},createElementFromHTML(a){var b=document.createElement("div");return b.innerHTML=a,b.firstChild},submit(a,b){a.preventDefault();var c=new Event("kb-adv-form-start-submit");window.document.body.dispatchEvent(c);var d=b.querySelector(".kb-adv-form-submit-button"),e=window.kadenceAdvancedForm.validateForm(b);if(e){var f=document.createElement("div");f.classList.add("kb-adv-form-loading"),f.innerHTML="<div class=\"kb-adv-form-loading-spin\"><div></div><div></div><div></div><div></div></div>",b.append(f),d.setAttribute("disabled","disabled"),d.classList.add("button-primary-disabled");fetch(kb_adv_form_params.ajaxurl,{method:"POST",body:e}).then(a=>{if(b.querySelector(".g-recaptcha")&&grecaptcha.reset(),d.removeAttribute("disabled"),d.classList.remove("button-primary-disabled"),b.querySelector(".kb-adv-form-loading").remove(),200<=a.status&&400>a.status)return a.json()}).then(a=>{var c=a;if(c.success){const a=c?.submissionResults;var d=new CustomEvent("kb-advanced-form-success",{detail:{uniqueId:b.querySelector("input[name=\"_kb_adv_form_id\"]")?b.querySelector("input[name=\"_kb_adv_form_id\"]").value:"",submissionResults:a}});window.document.body.dispatchEvent(d),c.redirect?window.location.replace(c.redirect):(window.kadenceAdvancedForm.insertAfter(window.kadenceAdvancedForm.createElementFromHTML(c.html),b),c?.hide?b.remove():window.kadenceAdvancedForm.clearForm(b))}else c.data&&(window.kadenceAdvancedForm.insertAfter(window.kadenceAdvancedForm.createElementFromHTML(c.data.html),b),c.data.required&&b.querySelector("[name=\""+c.data.required+"\"]")&&window.kadenceAdvancedForm.markError(b.querySelector("[name=\""+c.data.required+"\"]"),"required",b))}).catch(function(){console.log("Connection error")})}},initForms(){var a=document.querySelectorAll("form.kb-advanced-form");if(a.length)for(var b=function(a){return function(b){window.kadenceAdvancedForm.submit(b,a)}},c=0;c<a.length;c++)a[c].addEventListener("submit",b(a[c]))},initFloatingLabels(){var a=document.querySelectorAll(".kb-adv-form-label-style-float .kb-adv-form-text-type-input input, .kb-adv-form-label-style-float .kb-adv-form-text-type-input textarea");if(a.length)for(var b=function(a){return function(){a.parentNode.classList.add("kb-form-field-focus")}},c=function(a){return function(){a.value||a.parentNode.classList.remove("kb-form-field-focus")}},d=0;d<a.length;d++)a[d].value&&a[d].parentNode.classList.add("kb-form-field-focus"),a[d].addEventListener("focus",b(a[d])),a[d].addEventListener("blur",c(a[d]))},init:function(){return"undefined"!=typeof kb_adv_form_params&&void(window.kadenceAdvancedForm.initForms(),window.kadenceAdvancedForm.initFloatingLabels())}},"loading"===document.readyState?document.addEventListener("DOMContentLoaded",window.kadenceAdvancedForm.init):window.kadenceAdvancedForm.init()})();