(()=>{"use strict";const e=window.wp.i18n;document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll(".ablocks-form-builder__field").forEach(r=>{!function(r){console.log("form element ",r);const t=r?.querySelector(".ablocks-form-builder__input"),s=r?.getAttribute("data-required"),o=t?.getAttribute("type"),l=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,a=/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/,c=e=>l.test(e),i=e=>a.test(e);t&&("true"===s&&t?.addEventListener("focusout",()=>{if(""===t.value.trim()){r.classList.add("error-msg");const t=r.querySelector(".ablocks-block-error-msg");t&&(t.textContent=(0,e.__)("This field is required","ablocks"))}else if("email"!==o||c(t.value.trim())){if("url"===o&&!i(t.value.trim())){r.classList.add("error-msg");const t=r.querySelector(".ablocks-block-error-msg");t&&(t.textContent=(0,e.__)("Please enter a valid URL","ablocks"))}}else{r.classList.add("error-msg");const t=r.querySelector(".ablocks-block-error-msg");t&&(t.textContent=(0,e.__)("Please enter a valid Email","ablocks"))}}),t?.addEventListener("input",()=>{if(""!==t.value.trim())if("email"!==o||c(t.value.trim()))if("url"!==o||i(t.value.trim())){r.classList.remove("error-msg");const t=r.querySelector(".ablocks-block-error-msg");t&&(t.textContent="true"===s?(0,e.__)("This field is required","ablocks"):"")}else{r.classList.add("error-msg");const t=r.querySelector(".ablocks-block-error-msg");t&&(t.textContent=(0,e.__)("Please enter a valid URL","ablocks"))}else{r.classList.add("error-msg");const t=r.querySelector(".ablocks-block-error-msg");t&&(t.textContent=(0,e.__)("Please enter a valid Email","ablocks"))}else if("true"===s){r.classList.add("error-msg");const t=r.querySelector(".ablocks-block-error-msg");t&&(t.textContent=(0,e.__)("This field is required","ablocks"))}else r.classList.remove("error-msg")}))}(r)})})})();