angular.module("app").controller("DropEditWindowController",["$windowScope","activeDrop","activeTemplate","dropLoaded","modal","core","utils","state","delta","message",function(scope,activeDrop,activeTemplate,dropLoaded,modal,core,utils,state,delta,message){scope.utils=utils,scope.activeDrop=null,scope.activeTemplate=activeTemplate,scope.state=state,scope.path="drop["+activeDrop._internal.guid+"]",scope.backupHistory=null,scope.cachingState=!1,delta.loadDrop(activeDrop,!1).then((function(e){scope.activeDrop=e,scope.cachingState=utils.Drops.getCachingState(scope.activeDrop),dropLoaded(e)}),(function(e){message.error("Drop Daten konnten nicht geladen werden.",activeDrop._internal.name+": "+(e&&e.responseText?e.responseText:e)),utils.Drops.activateDrop(null)})),scope.showInsertConditionsModal=function(){modal.show("InsertConditionsModal",(function(e){e&&(scope.activeDrop._internal=e._internal)}),{drop:scope.activeDrop})},scope.showLanguageModal=function(){var e=scope.activeDrop._internal.dropId;modal.show("LanguageModal",(function(t){t&&(angular.isObject(core.settings.lang)||(core.settings.lang={}),core.settings.lang[e]=t)}),{template:activeTemplate,dropperUserLang:core.settings.lang&&core.settings.lang[e]?core.settings.lang[e]:{}})},scope.showDropConfigModal=function(){modal.show("DropConfigModal",(function(){}),{activeDrop:activeDrop,activeTemplate:activeTemplate,activePath:scope.path})},scope.showDropContainerModal=function(){modal.show("DropContainerModal",(function(e){e&&(!1===e.active?delete activeDrop._internal.container:activeDrop._internal.container=e)}),{activeDrop:activeDrop,activeTemplate:activeTemplate})},scope.showCachingModal=function(){modal.show("CachingModal",(function(e){e&&(scope.activeDrop._internal=e._internal)}),{drop:scope.activeDrop})};var evalCondition=function(condition){if(!angular.isDefined(condition)||null===condition)return!0;if(!0===condition)return!0;if(!1===condition)return!1;if(!angular.isString(condition))return!0;if(!condition.length)return!0;var drop=scope.activeDrop,self=scope.activeDrop;try{var result=eval("("+condition+") ? true : false");return result}catch(e){return!1}return!1};scope.isConfigureable=function(){return!!scope.activeTemplate&&(angular.isDefined(scope.activeTemplate.showsConfig)?evalCondition(scope.activeTemplate.showsConfig):!!(scope.activeTemplate&&angular.isArray(scope.activeTemplate.config)&&scope.activeTemplate.config.length))},scope.cachingAvailable=function(){return utils.Drops.canBeCached(scope.activeDrop)},scope.isInsertable=function(){return!!scope.activeTemplate&&(!angular.isDefined(scope.activeTemplate.showsInsertConditions)||evalCondition(scope.activeTemplate.showsInsertConditions))},scope.hasContainerSettings=function(){return!!scope.activeTemplate&&(!1!==scope.activeTemplate.container&&(!angular.isDefined(scope.activeTemplate.showsContainerSettings)||evalCondition(scope.activeTemplate.showsContainerSettings)))},scope.hasLangSettings=function(){return!(!scope.activeTemplate||!scope.activeTemplate.lang)},scope.hasSettings=function(){return!!scope.activeTemplate&&(angular.isDefined(scope.activeTemplate.showsSettings)?evalCondition(scope.activeTemplate.showsSettings):!(!angular.isArray(scope.activeTemplate.settings)||!scope.activeTemplate.settings.length))},scope.loadBackupHistory=function(){scope.backupHistory=null,scope.activeDrop&&(drop=scope.activeDrop,drop&&drop._internal&&drop._internal.guid&&$.ajax({url:core.shopURL,dataType:"JSON",type:"POST",data:{kk_dropper_get_drop_backup:drop._internal.guid,kk_dropper_admin_pass:core.adminSecret},success:function(e){scope.$apply((function(){scope.backupHistory=e}))},error:function(e){console.error("could not load backup history",e)}}))},scope.restoreBackupState=function(e){let t=core.settings.drops.indexOf(scope.activeDrop);if(!(t<0)){var o=e.drop,n={id:-1,user:o._internal.revision&&o._internal.revision.user?o._internal.revision.user:"Unbekannter Nutzer",timestamp:o._internal.revision&&o._internal.revision.timestamp?o._internal.revision.timestamp:null};o._internal.revision=n,core.settings.drops[t]=o,delta.setChanged(o,!0),utils.Drops.activateDrop(o)}},scope.$watch("activeDrop._internal.cache",(e,t)=>{scope.activeDrop&&scope.activeDrop&&(scope.cachingState=utils.Drops.getCachingState(scope.activeDrop))},!0)}]);