(function(){"use strict";window.kadenceForm={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-form-has-error")||c.classList.add("kb-form-has-error"),a.classList.add("has-error"),b){"required"===b?(d=a.getAttribute("data-required-message"),d&&""!==d&&void 0!==d||(d=a.getAttribute("data-label"),(!d||""===d||void 0===d)&&(d=kadence_blocks_form_params.item),d=d+" "+kadence_blocks_form_params[b])):"mismatch"===b?(d=a.getAttribute("data-mismatch-message"),d&&""!==d&&void 0!==d||(d=a.getAttribute("data-label"),(!d||""===d||void 0===d)&&(d=kadence_blocks_form_params.item),d=d+" "+kadence_blocks_form_params[b])):"validation"===b?(d=a.getAttribute("data-validation-message"),d&&""!==d&&void 0!==d||(d=a.getAttribute("data-label"),(!d||""===d||void 0===d)&&(d=kadence_blocks_form_params.item),d=d+" "+kadence_blocks_form_params[b])):void 0;var e=a.parentNode.querySelector(".kb-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-form-error-msg"),g.classList.add("kadence-blocks-form-warning"),g.setAttribute("role","alert"),g.innerHTML=d,a.classList.contains("kb-checkbox-style")?a.parentNode.append(g):window.kadenceForm.insertAfter(g,a)}1===window.kadenceForm.error_item&&a.focus(),window.kadenceForm.error_item++},addErrorNotice(a){var b=a.getAttribute("data-error-message");b&&""!==b&&void 0!==b||(b=kadence_blocks_form_params.error_message);var c=document.createElement("div");c.classList.add("kadence-blocks-form-message"),c.classList.add("kadence-blocks-form-warning"),c.innerHTML=b,window.kadenceForm.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-form-has-error")&&a.classList.remove("kb-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-form-error-msg");d&&d.remove()}var e=document.querySelectorAll(".kadence-blocks-form-message");if(e.length)for(var c=0;c<e.length;c++)e[c].remove();var f=a.querySelectorAll(".kb-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.kadenceForm.removeErrors(a);var d=a.querySelectorAll("[data-required=\"yes\"]");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.kadenceForm.markError(d[e],c,a));break;case"tel":g=d[e].value.trim(),""===g&&(b=!0,c="required",window.kadenceForm.markError(d[e],c,a));break;case"accept":!1==d[e].checked&&(b=!0,c="required",console.log("here"),window.kadenceForm.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.kadenceForm.markError(d[e],c,a)):(!g||"-1"===g)&&(b=!0,c="required",window.kadenceForm.markError(d[e],c,a));break;case"radio":var h=d[e].querySelector("input:checked");h||(b=!0,c="required",window.kadenceForm.markError(d[e],c,a));break;case"checkbox":var h=d[e].querySelector("input:checked");h||(b=!0,c="required",window.kadenceForm.markError(d[e],c,a));break;case"email":var g=d[e].value.trim();""===g?""===g&&(b=!0,c="required",window.kadenceForm.markError(d[e],c,a)):!window.kadenceForm.isValidEmail(g)&&(b=!0,c="validation",window.kadenceForm.markError(d[e],c,a));break;case"url":var g=d[e].value.trim();""===g?""===g&&(b=!0,c="required",window.kadenceForm.markError(d[e],c,a)):!window.kadenceForm.isValidURL(g)&&(b=!0,c="validation",window.kadenceForm.markError(d[e],c,a));}}if(b)return window.kadenceForm.addErrorNotice(a),!1;var i=new FormData(a);return i.set("_kb_form_verify",kadence_blocks_form_params.nonce),i=new URLSearchParams(i),i},createElementFromHTML(a){var b=document.createElement("div");return b.innerHTML=a,b.firstChild},submit(a,b){a.preventDefault();var c=new Event("kb-form-start-submit");window.document.body.dispatchEvent(c);var d=b.querySelector(".kb-forms-submit"),e=window.kadenceForm.validateForm(b);if(e){var f=document.createElement("div"),g=!1;f.classList.add("kb-form-loading"),f.innerHTML="<div class=\"kb-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");var h=new XMLHttpRequest;h.open("POST",kadence_blocks_form_params.ajaxurl,!0),h.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),h.onload=function(){if(200<=this.status&&400>this.status){var a=JSON.parse(this.response);if(a.success){var c=new CustomEvent("kb-form-success",{detail:b.querySelector("input[name=\"_kb_form_id\"]")?b.querySelector("input[name=\"_kb_form_id\"]").value:""});window.document.body.dispatchEvent(c),a.redirect?(g=!0,window.location=a.redirect):(window.kadenceForm.insertAfter(window.kadenceForm.createElementFromHTML(a.html),b),b.querySelector(".g-recaptcha")&&grecaptcha.reset(),window.kadenceForm.clearForm(b))}else a.data&&(window.kadenceForm.insertAfter(window.kadenceForm.createElementFromHTML(a.data.html),b),a.data.required&&b.querySelector("[name=\""+a.data.required+"\"]")&&window.kadenceForm.markError(b.querySelector("[name=\""+a.data.required+"\"]"),"required",b))}b.querySelector(".g-recaptcha")&&grecaptcha.reset(),g||(d.removeAttribute("disabled"),d.classList.remove("button-primary-disabled")),b.querySelector(".kb-form-loading").remove()},h.onerror=function(){console.log("Connection error")},h.send(e.toString())}},checkParentClass(a,b){return!!a?.className&&(0<=a.className.split(" ").indexOf(b)?a.id:a.parentNode&&window.kadenceForm.checkParentClass(a.parentNode,b))},verifySource(a){var b=a.querySelector("input[name=\"_kb_form_post_id\"]");if(b&&(!b.value||"block-unknown"===b.value)){var c=window.kadenceForm.checkParentClass(a.parentNode,"widget_block");c&&(b.value=c)}},initForms(){var a=document.querySelectorAll("form.kb-form");if(a.length)for(var b=function(a){return function(b){window.kadenceForm.submit(b,a)}},c=0;c<a.length;c++)window.kadenceForm.verifySource(a[c]),a[c].addEventListener("submit",b(a[c]))},init:function(){return"undefined"!=typeof kadence_blocks_form_params&&void window.kadenceForm.initForms()}},"loading"===document.readyState?document.addEventListener("DOMContentLoaded",window.kadenceForm.init):window.kadenceForm.init()})();