!function(e){formintorjs.define(["admin/builder/drag-drop","admin/builder/builder/field","admin/models/fields-collection","admin/builder/builder/wrapper","admin/popup/confirm"],function(i,t,r,d,n){return Backbone.View.extend({className:"wpmudev-builder--form-wrappers",fields:!1,wrappers:!1,grid:!1,initialize:function(e){return this.listenTo(Forminator.Events,"forminator:dnd:field:select",this.make_field_active),this.listenTo(Forminator.Events,"sidebar:settings:updated",this.settings_updated),this.listenTo(Forminator.Events,"sidebar:clone:field",this.clone_field),this.listenTo(Forminator.Events,"sidebar:delete:field",this.confirm_delete_field),this.render()},render:function(){var e=this;this.$el.html("");var r=0;this.wrappers=this.model.get("wrappers"),this.grid={},this.wrappers.each(function(n){var s=n.get("fields"),l=new d({model:n});e.$el.append(l.$el),e.grid[r]=new i(l,n,!1,"wrapper",e.model),e.grid[r].fields={},s.each(function(d){var s=new t({model:d,layout:e.model}),o=d.get("element_id"),a=o.split("-"),f=a[0],m=a[1];Forminator.Utils.is_randomed_field_id(o)||Forminator.Utils.is_field_id_exist(f,m)||Forminator.Utils.set_increment_field_id(f,m),l.$el.append(s.$el),e.grid[r].fields[d.get("element_id")]=new i(s,d,n,"field",e.model)}),r++}),Forminator.Grid=this.grid},clone_field:function(e){var i=this.get_wrapper_by_field(e),t=this.wrappers.model_index(i);if(!Forminator.Utils.ensure_max_of_type_field(this.wrappers,"captcha",1,e))return!1;var r=e.clone_deep(),d=new Forminator.Models.Wrapper({fields:new Forminator.Collections.Fields(r)});d.set("wrapper_id",Forminator.Utils.get_unique_id("wrapper")),r.set("cols",12),r.set("element_id",Forminator.Utils.get_increment_field_id(r)),this.wrappers.add(d,{silent:!0});var n=this.wrappers.model_index(d);this.wrappers.move_to(t+1,n),Forminator.Events.trigger("forminator:sidebar:open:settings",r),this.render(),this.make_field_active(r.cid)},get_wrapper_by_field:function(e){var i=!1;return this.wrappers.each(function(t){t.get("fields").each(function(r){r.get_id()===e.get_id()&&(i=t)})}),i},confirm_delete_field:function(e){var i=this,t="";_.isUndefined(e.get("field_label"))||_.isEmpty(e.get("field_label"))?(t=e.get("type"),t=Forminator.Utils.ucfirst(t)):t=e.get("field_label");new n({confirmation_message:Forminator.l10n.popup.confirm_field_delete+": <strong>"+t+"</strong>",confirm_callback:function(){this.close(),i.delete_field(e)}});return!1},delete_field:function(i){var t=this.get_wrapper_by_field(i);if(!1!==t){var r=t.get("fields"),d=(this.wrappers.model_index(t),t.fields_count());if(r.remove(i,{silent:!0}),d>1){var n=12/r.length;r.update_cols(n)}else this.wrappers.remove(t,{silent:!0});e("#wpmudev-sidebar-settings").find(".wpmudev-sidebar").removeClass("wpmudev-is_active"),Forminator.Events.trigger("forminator:sidebar:close:settings"),Forminator.Events.trigger("dnd:reload:fields")}},settings_updated:function(e){e.trigger("forminator:field:settings:updated");var i=Forminator.Utils.get_fields_models(this.wrappers,[e.cid]),t=new r(i),d=t.get_fields_related_to(e);_.each(d,function(e){e.trigger("forminator:field:settings:updated")}),this.make_field_active(e.cid)},make_field_active:function(i){var t=e("#wpmudev-field-"+i+" .wpmudev-form-field");if(0===t.length)return!1;t.addClass("wpmudev-is_active"),e("html, body").animate({scrollTop:t.offset().top-(e(window).height()-t.outerHeight(!0))/2},0)}})})}(jQuery);