(()=>{function e(n,e,o){var s,t,r=this,l=(_.assign(r,{filterAsset:function(e){return!r.ownerAllAssignedRoles||_.get(r.ownerAllAssignedRoles,[e.id,"length"])},onApply:function(e,n){return r.onChangeRoles({managedObjectId:n,roles:e})},$onChanges:function(e){(e.assignedRoles||e.ownerAssignedRoles)&&l.then(u);e.expandGroups&&r.expandGroups&&n.expandAll(s,i)},loadChildren:function(e){e.isOpened?(e._subGroups=[],e.isOpened=!1,i()):(n.loadChildren(e).then(i),e.isOpened=!0)},title:function(e){var n=e._subGroups,s=o.getString("Click to fetch subgroups");Array.isArray(n)&&e.isOpened&&(s=0<n.length?o.getPlural(n.length,"1 subgroup","{{$count}} subgroups",{}):o.getString("No subgroups"));return s}}),t=r.user.owner,n.listRootGroups({onlyRootsUser:t}).then(function(e){s=e,i()}));function i(){r.flatAssetTree=n.flatTree(s),u()}function u(){var e;r.assignedRoles&&(r.inheritedRoles=a(r.flatAssetTree,r.assignedRoles)),r.ownerAssignedRoles&&(e=a(r.flatAssetTree,r.ownerAssignedRoles),r.ownerAllAssignedRoles=_.mergeWith(e,r.ownerAssignedRoles,function(e,n){return n?e?_.uniqBy(e.concat(n.roles),"id"):n.roles:e}))}function a(e,s){return _.reduce(e,function(e,n){return e[n.id]=_(n._parentGroups).map(function(e){return _.get(s,e.id)}).filter(_.identity).map(_.property("roles")).flatten().uniqBy("id").value(),e},{})}e.list().then(function(e){r.inventoryRoles=e})}e.$inject=["c8yUserInventoryRoles","c8yRoles","gettextCatalog"],angular.module("c8y.userRoles").component("c8yRolesAssetTree",{templateUrl:":::PLUGIN_PATH:::/rolesAssetTree/rolesAssetTree.html",controllerAs:"vm",controller:e,bindings:{user:"<",searchFilter:"<",assignedRoles:"<",ownerAssignedRoles:"<",expandGroups:"<",pageSize:"<",paginationOffset:"<",onChangeRoles:"&",onChangeItemCount:"&"}})})();