(function(e){define(["scripts/upfront/preset-settings/select-preset-panel","scripts/upfront/preset-settings/util","scripts/upfront/preset-settings/edit-preset-panel"],function(e,t,n){var r=Upfront.Views.Editor.Settings.Settings.extend({initialize:function(e){this.options=e,this.has_tabs=!1,this.presets=new Backbone.Collection(Upfront.mainData[this.mainDataCollection]||[]),this.showSelectPresetPanel(!1)},showSelectPresetPanel:function(t){this.selectPresetPanel=new e({model:this.model,presets:this.presets}),this.panels=_([this.selectPresetPanel]),this.listenTo(this.selectPresetPanel,"upfront:presets:new",this.createPreset),this.listenTo(this.selectPresetPanel,"upfront:presets:edit",this.editPreset),t&&this.render()},getPresetDefaults:function(e){return _.extend(this.presetDefaults,{id:e.toLowerCase().replace(/ /g,"-"),name:e})},updatePreset:function(e){var n,r;t.updatePresetStyle(this.styleElementPrefix.replace(/-preset/,""),e,this.styleTpl),Upfront.Util.post({action:"upfront_save_"+this.ajaxActionSlug+"_preset",data:e}),_.each(Upfront.mainData[this.mainDataCollection],function(t,r){t.id===e.id&&(n=r)}),_.isUndefined(n)===!1&&Upfront.mainData[this.mainDataCollection].splice(n,1),Upfront.mainData[this.mainDataCollection].push(e)},createPreset:function(e){var t=this.getPresetDefaults(e);this.presets.add(t),this.model.set_property("preset",t.id),this.updatePreset(t),this.editPreset(t.id)},deletePreset:function(e){var t;Upfront.Util.post({data:e.toJSON(),action:"upfront_delete_"+this.ajaxActionSlug+"_preset"}),_.each(Upfront.mainData[this.mainDataCollection],function(n,r){n.id===e.get("id")&&(t=r)}),Upfront.mainData[this.mainDataCollection].splice(t,1),this.model.set_property("preset","default"),this.presets.remove(e),this.showSelectPresetPanel(!0)},editPreset:function(e){this.editPresetPanel=new n({model:this.model,preset:this.presets.findWhere({id:e}),stateFields:this.stateFields}),this.panels=_([this.editPresetPanel]),this.listenTo(this.editPresetPanel,"upfront:presets:update",this.updatePreset),this.listenTo(this.editPresetPanel,"upfront:presets:delete",this.deletePreset),this.$el.html(""),this.render()},get_title:function(){return this.panelTitle}});return r})})(jQuery);