!function(a){formintorjs.define(["admin/builder/appearance/appearance-settings","admin/builder/appearance/behaviour-settings","admin/builder/appearance/email-settings","admin/builder/appearance/advanced-settings","admin/builder/appearance/pagination-settings","admin/popup/ajax","text!admin/templates/appearance.html"],function(t,e,i,n,o,r,s){return Backbone.View.extend({mainTpl:Forminator.Utils.template(a(s).find("#appearance-main-tpl").html()),buttonsTpl:Forminator.Utils.template(a(s).find("#appearance-buttons-tpl").html()),events:{"click .forminator-save-changes":"save_changes","click .forminator-save-layout":"save_layout","click .wpmudev-button-back":"back_to_builder","click .wpmudev-preview":"open_preview","change .wpmudev-input,.forminator-field-singular":"set_dirty"},has_pagination:!1,dirty:!1,initialize:function(a){return this.render()},render:function(){var n=this.model.get("wrappers");this.has_pagination=Forminator.Utils.has_field_type(n,"pagination"),Forminator.Events.trigger("forminator:sidebar:close:settings"),this.$el.html(this.mainTpl({has_pagination:this.has_pagination})),this.$el.append(this.buttonsTpl()),this.$el.find(".wpmudev-wizard--content").tabs(),this.$el.find(".wpmudev-tabs-mobile").on("change",function(t){a("."+a(this).val()+" a").click()}),a("#wpmudev-header h1").html(Forminator.l10n.appearance.settings_title),a("#wpmudev-header .wpmudev-button").hide();var r={appearance:t,behaviour:e,emails:i};this.has_pagination&&(r.pagination=o),this.append_settings(r);var s=this;a(window).off("beforeunload.forminator-leave-wizard-confirm"),a(window).on("beforeunload.forminator-leave-wizard-confirm",function(a){if(s.dirty)return Forminator.l10n.popup.save_alert}),this.init_select2()},back_to_builder:function(a){Forminator.navigate("builder",{trigger:!0})},cancel_builder:function(a){a.preventDefault(),window.location.href=Forminator.Data.modules.custom_form.form_list_url},open_preview:function(t){t.preventDefault();var e=a(t.target);e.hasClass("wpmudev-preview")||(e=e.closest(".wpmudev-preview"));var i=e.data("modal"),n=e.data("nonce"),o=e.data("form-id");this.open_preview_popup(i,n,o,Forminator.l10n.popup.preview_cforms+" - "+this.model.get("formName"),this.model.toJSON())},open_preview_popup:function(t,e,i,n,o){_.isUndefined(n)&&(n=Forminator.l10n.appearance.preview_form);var s=new r({action:t,nonce:e,data:o,id:i});Forminator.Popup.open(function(){a(this).append(s.el),a(".forminator-design--material").each(function(){var t=a(this),e=t.find(".forminator-input--wrap"),i=t.find(".forminator-textarea--wrap"),n=(t.find(".forminator-product"),t.find(".forminator-date")),o=t.find(".forminator-pagination--nav"),r=o.find("li");a('<span class="forminator-nav-border"></span>').insertAfter(r),e.prev(".forminator-field--label").addClass("forminator-floating--input"),i.prev(".forminator-field--label").addClass("forminator-floating--textarea"),n.hasClass("forminator-has_icon")?n.prev(".forminator-field--label").addClass("forminator-floating--date"):n.prev(".forminator-field--label").addClass("forminator-floating--input")})},{title:n})},save_changes:function(t){t.preventDefault(),this.validate()?(this.save(!1,!0),a(".wpmudev-preview").show()):(a(".wpmudev-wizard--content").tabs("option","active",0),a("html, body").animate({scrollTop:0},500))},save_layout:function(t){t.preventDefault(),this.validate()?this.save(!0,!0):(a(".wpmudev-wizard--content").tabs("option","active",0),a("html, body").animate({scrollTop:0},500))},save:function(t,e){var i=!1;if(e&&this.$el.find(".forminator-save").addClass("wpmudev-button-onload"),t){this.model.get("is_new")||!1||(this.model.set("is_new",!0),i=!0)}var n=this,o=Forminator.Utils.model_to_json(this.model),r=Forminator.Data.currentForm.formName||this.model.get("formName")||"",s=Forminator.Data.currentForm.formID||-1;a.post({url:Forminator.Data.ajaxUrl,data:{action:"forminator_save_builder_settings",formName:r,formID:s,data:o}}).success(function(a){if(n.dirty=!1,-1===s&&(Forminator.Data.currentForm.formID=a.data),e&&(setTimeout(function(){n.$el.find(".forminator-save").removeClass("wpmudev-button-onload")},500),t||Forminator.Notification.open("success",r+" "+Forminator.l10n.options.been_saved,4e3)),t){var o;i?(o=Forminator.Data.modules.custom_form.form_list_url,window.location.href=o+"&new=true&title="+r.replace(/ /g,"-")):(o=Forminator.Data.modules.custom_form.form_list_url,window.location.href=o+"&notification=true&title="+r.replace(/ /g,"-"))}}).error(function(){Forminator.Notification.open("error",Forminator.l10n.options.error_saving,5e3)})},validate:function(){var a=!1;return _.isEmpty(this.model.get("formName"))?(this.$el.find("#forminator-validate-name").show(),a=!0):this.$el.find("#forminator-validate-name").hide(),!a},init_select2:function(){Forminator.Utils.init_select2()},append_settings:function(a){var t=this;_.each(a,function(a,e){var i=new a({model:t.model});t.$el.find("#forminator-wizard-"+e).append(i.el)})},set_dirty:function(){this.dirty=!0}})})}(jQuery);