angular.module("app").controller("DuplicateModalController",["$modalScope","core","drops","utils","delta",function(n,e,r,o,a){n.drops=[].concat(r),n.utils=o,n.delayShow=!0,n.group={path:r.group||o.Group.pathFromName(n.drops[0]._internal.name),base:r.group||o.Group.pathFromName(n.drops[0]._internal.name)},r.group&&(n.group.path+=" (Kopie)");var buildCloneList=function(n,e,r){var a=[],t={level:e=e||0,drop:n,parent:r=r||null,guid:n._internal.guid};a.push(t);var l=o.Drops.getOutboundLinks(n,"inline");return l&&l.length?(l.forEach((function(n){a=a.concat(buildCloneList(n,e+1,t))})),a):a};n.getName=function(r){if(n.shouldClone(r)){var a=n.group.base,t=n.group.path,l=o.Group.pathFromName(r.drop._internal.name);l=0===l.indexOf(a)?o.Group.normalize(t+":"+l.replace(a,"")):o.Group.normalize(t+":"+l);var u=o.Group.normalize(l+": "+o.Group.baseName(r.drop._internal.name));return u+(function(n){for(var r=0;r<e.settings.drops.length;r++){var o=e.settings.drops[r];if(o&&o._internal&&o._internal.name===n)return!0}return!1}(u)?" (Kopie)":"")}return r.drop._internal.name},n.canClone=function(e){return!e.parent||a.isLoaded(e.drop)&&n.shouldClone(e.parent)},n.shouldClone=function(e){return n.canClone(e)&&n.clone[e.guid]},n.toggleMode=function(e){0!==e.level&&(n.clone[e.guid]=n.canClone(e)&&!n.clone[e.guid])};var buildClones=function(){var e={};n.depTree.forEach((function(r){if(n.shouldClone(r)&&!e[r.guid]){var a,t=(a=r.drop,o.Drops.duplicateObject(a));t._internal.name=n.getName(r),r.level>0&&(t._internal.selector="",t._internal.replaceMethod=""),e[r.guid]=t}}));var r,a,t,l,u={};for(var i in e)u[i]=e[i]._internal.guid;for(var p in e)for(var c in u){var d=u[c];e[p]=(r=e[p],a=c,t=d,l=void 0,l=(l=angular.toJson(r)).replace(new RegExp(a,"g"),t),angular.fromJson(l))}return Object.values(e)};n.applyOperations=function(){var r=buildClones();if(!r||!r.length)return close();r.forEach((function(n){e.settings.drops.push(n),a.setChanged(n)})),o.Drops.activateDrop(r[0]),n.close()},function(e,r){var o=[];e.forEach((function(n){o=o.concat(buildCloneList(n))}));var t=o.filter((function(n){return 0===n.level})),l=(o=o.filter((function(n){return 0===n.level||!t.filter((function(e){return e.guid===n.guid})).length}))).map((function(n){return n.drop}));a.loadDrops(l).then((function(){n.clone={},e.forEach((function(e){n.clone[e._internal.guid]=!0})),n.depTree=o,r&&r(o)}))}(n.drops,(function(){1===n.depTree.length?n.applyOperations():n.show()}))}]);