!function(e){formintorjs.define(["admin/builder/sidebar/field-settings","text!admin/templates/builder-sidebar.html"],function(t,i){return e("body").append('<div id="wpmudev-sidebar-settings" class="wpmudev-ui" />'),Backbone.View.extend({sidebarTpl:Forminator.Utils.template(e(i).find("#builder-sidebar-tpl").html()),tabsTpl:Forminator.Utils.template(e(i).find("#builder-sidebar-field-tabs-tpl").html()),field_settings_view:!1,events:{"click .forminator-sidebar-close":"destroy_sidebar"},initialize:function(e){return this.listenTo(Forminator.Events,"forminator:sidebar:open:settings",this.create_settings),this.listenTo(Forminator.Events,"forminator:sidebar:close:settings",this.destroy_settings),this.render()},render:function(){this.$el.html(this.sidebarTpl()),Forminator.Events.trigger("forminator:sidebar:rendered"),this.render_tabs(),this.init_drag()},render_tabs:function(){var e=Forminator.Data.fields;Forminator.Data.hasCaptcha||(e=_.filter(e,function(e){return"captcha"!==e.slug})),e=_.groupBy(e,"category");var t=this.get_headings(e);this.$el.append(this.tabsTpl({tabs:e,headings:t})),this.$el.find(".wpmudev-sort-fields").tabs(),Forminator.Events.trigger("forminator:field_tabs:rendered")},get_headings:function(e){var t=Forminator.Data.defaultTabs;return _.each(e,function(e,i){i=i.toLowerCase(),_.contains(t,i)||t.push(i)}),t},init_drag:function(){var t=this.$el.find(".draggable-element");_.each(t,function(t){var i=e(t);i.on("click",function(e){var t=i.data("shadowid");Forminator.Events.trigger("forminator:add:field:click",t)}),i.on("mousedown",function(t){var s=(e(".wpmudev-builder--form"),i.data("shadowid")),a=e("[data-shadow="+s+"]"),d=a.position(),n=a.offset(),r=a.outerHeight(),o=a.outerWidth(),l=i.clone(),m=i.outerWidth(),u=i.outerHeight();a.css({position:"absolute",top:t.pageY-(n.top-d.top)-r/2,left:t.pageX-(n.left-d.left)-o/2,visibility:"hidden",zIndex:-1}).one("mousedown",function(e){}).trigger(t).one("dragstart",function(t,s){i.addClass("field-drag-active"),e("body").append(l),l.addClass("element-dragging"),l.css({position:"absolute",left:t.pageX-m/2,top:t.pageY-u/2,zIndex:9999})}).on("drag",function(e,t){l.css({left:e.pageX-m/2,top:e.pageY-u/2})}).one("dragstop",function(e,t){i.removeClass("field-drag-active"),l.remove()})})})},create_settings:function(i){if(_.isUndefined(i.get("type")))return!1;var s=this,a=_.where(Forminator.Data.fields,{slug:i.get("type")})[0];this.field_settings_view=new t({model:this.model,field:i,field_settings:a}),e("#wpmudev-sidebar-settings").html(this.field_settings_view.el),e("#wpmudev-sidebar-settings").find(".wpmudev-sidebar").addClass("wpmudev-is_active"),e("body").addClass("wpmudev-sidebar-is_active"),setTimeout(function(){e("#wpmudev-sidebar-settings").find(".wpmudev-sidebar--wrap").addClass("wpmudev-show"),s.close_animation&&clearTimeout(s.close_animation),s.close_action&&clearTimeout(s.close_action)},10),Forminator.Events.trigger("forminator:field:settings:created")},destroy_settings:function(){var t=e("#wpmudev-sidebar-settings"),i=t.find(".wpmudev-sidebar"),s=t.find(".wpmudev-sidebar--wrap");if(s.removeClass("wpmudev-show").addClass("wpmudev-hide"),this.close_animation=setTimeout(function(){i.removeClass("wpmudev-is_active"),e("body").removeClass("wpmudev-sidebar-is_active"),s.removeClass("wpmudev-hide")},1e3),this.field_settings_view){var a=this;this.close_action=setTimeout(function(){a.field_settings_view&&(a.field_settings_view.cleanUp(),a.field_settings_view=!1)},1200)}Forminator.Events.trigger("forminator:field:settings:destroyed")},destroy_sidebar:function(t){t.preventDefault(),e("#wpmudev-sidebar").removeClass("wpmudev-show").addClass("wpmudev-hide"),setTimeout(function(){e("#wpmudev-sidebar").removeClass("wpmudev-is_active"),e("#wpmudev-sidebar").removeClass("wpmudev-hide"),e("body.wp-admin").removeClass("wpmudev-disabled--mobile")},1e3)}})})}(jQuery);