angular.module("app").service("state",["core","upgrade","packageManager","message","modal","delta","$timeout","$q","$rootScope",function(e,t,r,n,i,s,o,a,u){if(window.dropperState)return window.dropperState;var c=window.dropperState={activeDrop:null,activeDropLoading:null,dirty:!1,saveInProgress:!1,dashboardOpen:!0,isFrontendMode:!!window.kk_frontend_mode,requestPath:"",sidebar:{get width(){return+window.localStorage.getItem("kk_dropper.sidebarWidth")||360},set width(e){var t=angular.isNumber(e)?+e:360;window.localStorage.setItem("kk_dropper.sidebarWidth",t)}},history:{items:[],current:null,push:function(t){if(c.history.cleanup(),angular.isObject(t)&&!(e.settings.drops.indexOf(t)<0)){var r=c.history.items.indexOf(t);r>=0&&c.history.items.splice(r,1);var n=c.history.items.indexOf(c.history.current);c.history.items.splice(n+1),c.history.items.push(t),c.history.current=t}},back:function(e){c.history.cleanup();var t=c.history.items.indexOf(c.history.current);if(t<=0)return null;var r=c.history.items[t-1];return e?r:(c.history.current=r,c.history.current)},forward:function(e){c.history.cleanup();var t=c.history.items.indexOf(c.history.current);if(t>=c.history.items.length-1)return null;var r=c.history.items[t+1];return e?r:(c.history.current=r,c.history.current)},backPossible:function(){return c.history.cleanup(),c.history.items.indexOf(c.history.current)>0},forwardPossible:function(){c.history.cleanup();var e=c.history.items.indexOf(c.history.current);return e>=0&&e<c.history.items.length-1},cleanup:function(){for(var t=0;t<c.history.items.length;t++){let r=c.history.items[t];e.settings.drops.indexOf(r)>=0||(c.history.items.splice(t,1),t--)}}},setDirtySaveState:function(e){c.dirty=!!e},showDashboard:function(){c.dashboardOpen=!0},hideDashboard:function(){c.dashboardOpen=!1},toggleDashboard:function(){c.dashboardOpen=!c.dashboardOpen},verifyChanges:function(){console.log("verfiying changes..."),t.updateMultiLangFields(e.settings),e.fn.checkLicenceErrors(),e.fn.checkDropErrors(),e.fn.trigger("verifyChanges"),c.showDashboard(),r.checkForcedUpgrades()},loadSettings:function(){let t=e.fn.loadSettings();return t.then((function(){s.reset()})),t},saveSettings:function(t){return t=t||"",$("input, textarea, select, .ng-model-change-save").trigger("save"),a((function(r,i){o((function(){c.saveInProgress=!0;var u=e.fn.trigger("beforeSave",[]);a.all(u).then((function(){s.saveDeltaSettings(!1,t).then((function(t){o((function(){c.saveInProgress=!1,c.setDirtySaveState(!!s.changed.length)})),e.fn.trigger("saveSettings",[null,t]),r(t)}),(function(t){o((function(){c.saveInProgress=!1,n.error("Beim Speichern ist ein Fehler aufgetreten: ",angular.fromJson(t).statusText||t)})),e.fn.trigger("saveSettings",[t,null]),i(t)}))})).catch((function(e){n.error("Vor dem Speichern ist ein Fehler aufgetreten:",e)}))}),50)}))}};return s.on("change, unchange, remove",(function(e){(s.changed.length||s.removed.length)&&c.setDirtySaveState(!0)})),window.dropperState}]);