!function(e,a){const r={errorMessages:{},init(){setInterval((function(){"undefined"!=typeof tinyMCE&&tinyMCE.triggerSave(),e(".automatewoo-field-wrap textarea.wp-editor-area").each((function(){e(this).attr("data-automatewoo-validate","variables"),r.validateField(e(this))}))}),2e3),e(document.body).on("keyup blur change","[data-automatewoo-validate]",(function(a){r.validateField(e(a.target))})),r.validateAllFields()},validateAllFields(){e("[data-automatewoo-validate]").each((function(){r.validateField(e(this))}))},validateField(e){if(!AW.workflow)return;const a=[],t=e.val();r.clearFieldErrors(e);const i=AW.Validate.getVariablesFromText(t);if(r.fieldSupports("variables",e)){const e=AW.workflow.get("trigger");_.each(i,(function(t){const i=r.isVariableValidForTrigger(t,e);!0!==i&&a.push(r.getErrorMessage(i,r.getVariableWithoutParams(t)))}))}else i&&a.push(r.getErrorMessage("noVariablesSupport"));a.length&&r.setFieldErrors(e,a)},setFieldErrors(e,a){e.addClass("automatewoo-field--invalid");const r=e.parents(".automatewoo-field-wrap:first");r.append('
');const t=r.find(".automatewoo-field-errors");e.is(".wp-editor-area")&&r.find(".wp-editor-container").addClass("automatewoo-field--invalid"),_.each(a,(function(e){t.append('
'+e+"
")}))},clearFieldErrors(e){const a=e.parents(".automatewoo-field-wrap:first");e.removeClass("automatewoo-field--invalid"),e.is(".wp-editor-area")&&a.find(".wp-editor-container").removeClass("automatewoo-field--invalid"),a.find(".automatewoo-field-errors").remove()},fieldSupports(e,a){const r=a.data("automatewoo-validate").split(" ");return-1!==_.indexOf(r,e)},isVariableValidForTrigger(e,a){if(!a)return"noTrigger";const t=r.getDataTypeFromVariable(e);if(t&&-1===_.indexOf(a.supplied_data_items,t))return"invalidDataType";const i=r.getDataFieldFromVariable(e),o=AW.workflow.get("variables");return!o||!o[t]||-1!==o[t].indexOf(i)||"invalidVariable"},getVariablesFromText(e){const a=e.match(/{{(.*?)}}/g);return!!a&&(_.each(a,(function(e,r){a[r]=e.replace(/{|}/g,"").trim()})),a)},getVariableWithoutParams(e){return e.replace(/(\|.*)/,"")},getDataTypeFromVariable(e){return-1!==e.indexOf(".")&&e.replace(/(\..*)/,"")},getDataFieldFromVariable(e){const a=(e=r.getVariableWithoutParams(e)).indexOf(".");return-1!==a&&e.substring(a+1).trim()},getErrorMessage(e,a){if(!r.errorMessages[e])return"Unknown error, please try refreshing your browser.";let t=r.errorMessages[e];return"string"==typeof a&&(t=t.replace("%s",a)),t}};AW.Validate=r,r.errorMessages=a}(jQuery,automatewooValidateLocalizedErrorMessages); //# sourceMappingURL=validate.min.js.map