!function(i,t,e,n){"use strict";function s(t,e){this.element=t,this.$el=i(this.element),this.settings=i.extend({},o,e),this._defaults=o,this._name=r,this.init()}var r="forminatorFrontCondition",o={fields:{},relations:{}};i.extend(s.prototype,{init:function(){var t=this;this.add_missing_relations(),this.$el.find(".forminator-field input, .forminator-field select").change(function(e){var n=i(this),s=n.closest(".forminator-col").attr("id");if(void 0===s&&(s=n.attr("id")),!t.has_relations(s))return!1;t.get_relations(s).forEach(function(i){var e=t.get_field_logic(i),n=e.action,s=e.rule,r=e.conditions,o=0;r.forEach(function(i){t.is_applicable_rule(i)&&o++}),"all"===s&&o===r.length||"any"===s&&o>0?t.toggle_field(i,n,"valid"):t.toggle_field(i,n,"invalid")})}),this.$el.find(".forminator-field input, .forminator-field select").change(),this.init_events()},init_events:function(){var i=this;this.$el.on("forminator.front.condition.restart",function(t){i.on_restart(t)})},on_restart:function(i){this.$el.find(".forminator-field input, .forminator-field select").change()},add_missing_relations:function(){var i=this,t={};if(void 0!==this.settings.fields){var e=this.settings.fields;Object.keys(e).forEach(function(n){e[n].conditions.forEach(function(e){var s=e.field;i.has_relations(s)||(void 0===t[s]&&(t[s]=[]),t[s].push(n))})})}Object.keys(t).forEach(function(e){i.settings.relations[e]=t[e]})},get_field_logic:function(i){return void 0===this.settings.fields[i]?[]:this.settings.fields[i]},has_relations:function(i){return void 0!==this.settings.relations[i]},get_relations:function(i){return this.has_relations(i)?this.settings.relations[i]:[]},get_field_value:function(t){var e=this.get_form_field(t),n=e.val();return this.field_is_radio(e)?n=e.filter(":checked").val():this.field_is_checkbox(e)&&(n=[],e.each(function(){i(this).is(":checked")&&n.push(i(this).val().toLowerCase())})),n||""},field_is_radio:function(t){var e=!1;return t.each(function(){if("radio"===i(this).attr("type"))return e=!0,!1}),e},field_is_checkbox:function(t){var e=!1;return t.each(function(){if("checkbox"===i(this).attr("type"))return e=!0,!1}),e},get_form_field:function(i){var t=this.$el.find("#"+i+"-field");return 0===t.length&&(t=this.$el.find("input[name="+i+"]"),0===t.length&&(t=this.$el.find("textarea[name="+i+"]"),0===t.length&&(t=this.$el.find('input[name="'+i+'[]"]'),0===t.length&&(t=this.$el.find("#"+i))))),t},is_numeric:function(i){return!isNaN(parseFloat(i))&&isFinite(i)},is_applicable_rule:function(i){if(void 0===i)return!1;var t=this.get_field_value(i.field),e=i.value,n=i.operator;return this.is_matching(t,e,n)},is_matching:function(t,e,n){var s=Array.isArray(t);switch(s||(t=t?t.toLowerCase():""),e=e?e.toLowerCase():"",n){case"is":return s?i.inArray(e,t)>-1:t===e;case"is_not":return s?-1===i.inArray(e,t):t!==e;case"is_great":return t=+t,e=+e,!(!this.is_numeric(t)||!this.is_numeric(e))&&t>e;case"is_less":return t=+t,e=+e,!(!this.is_numeric(t)||!this.is_numeric(e))&&t<e;case"contains":return this.contains(t,e);case"starts":return t.startsWith(e);case"ends":return t.endsWith(e)}return!1},contains:function(i,t){return i.toLowerCase().indexOf(t)>=0},toggle_field:function(i,t,e){var n=this.get_form_field(i),s=n.closest(".forminator-col");"show"===t&&("valid"===e?s.removeClass("forminator-hidden"):s.addClass("forminator-hidden")),"hide"===t&&("valid"===e?s.addClass("forminator-hidden"):s.removeClass("forminator-hidden"))}}),i.fn[r]=function(t){return this.each(function(){i.data(this,r)||i.data(this,r,new s(this,t))})}}(jQuery,window,document);