angular.module("app").service("state",["core","upgrade","packageManager","message","modal","delta","$timeout","$q","$rootScope",function(e,t,r,n,i,o,s,a,c){if(window.dropperState)return window.dropperState;var u=new URLSearchParams(window.location.search),d=window.dropperState={activeDrop:null,activeDropLoading:null,dirty:!1,saveInProgress:!1,dashboardOpen:!0,isFrontendMode:!!window.kk_frontend_mode,frontendModeSource:window.kk_frontend_mode?u.get("kk_dropper_frontend_editor"):null,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(d.history.cleanup(),angular.isObject(t)&&!(e.settings.drops.indexOf(t)<0)){var r=d.history.items.indexOf(t);r>=0&&d.history.items.splice(r,1);var n=d.history.items.indexOf(d.history.current);d.history.items.splice(n+1),d.history.items.push(t),d.history.current=t}},back:function(e){d.history.cleanup();var t=d.history.items.indexOf(d.history.current);if(t<=0)return null;var r=d.history.items[t-1];return e?r:(d.history.current=r,d.history.current)},forward:function(e){d.history.cleanup();var t=d.history.items.indexOf(d.history.current);if(t>=d.history.items.length-1)return null;var r=d.history.items[t+1];return e?r:(d.history.current=r,d.history.current)},backPossible:function(){return d.history.cleanup(),d.history.items.indexOf(d.history.current)>0},forwardPossible:function(){d.history.cleanup();var e=d.history.items.indexOf(d.history.current);return e>=0&&e<d.history.items.length-1},cleanup:function(){for(var t=0;t<d.history.items.length;t++){let r=d.history.items[t];e.settings.drops.indexOf(r)>=0||(d.history.items.splice(t,1),t--)}}},setDirtySaveState:function(e){d.dirty=!!e},showDashboard:function(){d.dashboardOpen=!0},hideDashboard:function(){d.dashboardOpen=!1},toggleDashboard:function(){d.dashboardOpen=!d.dashboardOpen},verifyChanges:function(){console.log("verfiying changes..."),t.updateMultiLangFields(e.settings),e.fn.checkLicenceErrors(),e.fn.checkDropErrors(),e.fn.trigger("verifyChanges"),d.showDashboard(),r.checkForcedUpgrades()},loadSettings:function(){let t=e.fn.loadSettings();return t.then((function(){o.reset()})),t},saveSettings:function(t){return t=t||"",$("input, textarea, select, .ng-model-change-save").trigger("save"),a((function(r,i){s((function(){d.saveInProgress=!0;var c=e.fn.trigger("beforeSave",[]);a.all(c).then((function(){o.saveDeltaSettings(!1,t).then((function(t){s((function(){d.saveInProgress=!1,d.setDirtySaveState(!!o.changed.length)})),e.fn.trigger("saveSettings",[null,t]),r(t)}),(function(t){s((function(){d.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 o.on("change, unchange, remove",(function(e){(o.changed.length||o.removed.length)&&d.setDirtySaveState(!0)})),window.dropperState}]);