angular.module("app").controller("GroupImproveModalController",["$modalScope","core","utils","delta",function(e,n,o,r){e.renames={};var normalizeName=function(e){return e.replace(/([A-Za-z])-([A-Za-z])/g,"$1 $2")},optimizeName=function(e,n){e=normalizeName(e);for(let o of n)0===e.toLowerCase().indexOf(o.name.toLowerCase()+" ")&&(e=(e=(e=o.name+": "+e.substring(o.name.length)).replace(/\ {2,}/gm," ")).replace(/:{2,}/gm,":"));return e};e.getRenameCount=function(){return e.renames.filter((function(e){return!!e.take})).length},e.applyOperations=function(){e.renames.filter((function(e){return!!e.take})).forEach((function(e){e.drops.forEach((function(e){e.drop._internal.name=e.newName,r.setChanged(e.drop)}))})),e.close(!0)},function(){let r=[],t=function(e){let n={};for(let o of e){let e=normalizeName(o).split(":");e.pop(),e=e.join(":");let r=e.split(" "),t="";for(let e of r){t=(t+" "+e).trim();let o=t.toLowerCase();n[o]?n[o].count++:n[o]={path:o,name:t,count:1}}}n=Object.values(n),n=n.filter((function(e){return e.count>1})),n=n.sort((function(e,n){return n.name.length-e.name.length}));for(let e of n)for(let o of n)e!==o&&o.count===e.count&&0===e.path.indexOf(o.path)&&(o.ignore=!0);return n=n.filter((function(e){return!e.ignore})),n}(n.settings.drops.map((function(e){return e._internal.name})));for(let e of n.settings.drops){let n=e._internal.name,o=optimizeName(n,t);o!==n&&r.push({oldName:n,newName:o,drop:e})}var a={};r.forEach((function(e){var n=o.Group.pathFromName(e.oldName),r=o.Group.pathFromName(e.newName);n!==r&&(a[n]||(a[n]={oldGroup:n,newGroup:r,drops:[],take:!0}),a[n].drops.push({drop:e.drop,oldName:e.oldName,newName:e.newName}))})),a=(a=Object.values(a)).sort((function(e,n){return 0===e.newGroup.indexOf(n.newGroup)?-1:0===n.newGroup.indexOf(e.newGroup)?1:e.newGroup<n.newGroup?-1:n.newGroup<e.newGroup?1:0})),e.renames=a}()}]);