function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(r,e){var n;if(r)return"string"==typeof r?_arrayLikeToArray(r,e):"Map"===(n="Object"===(n={}.toString.call(r).slice(8,-1))&&r.constructor?r.constructor.name:n)||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(r,e):void 0}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r)}function _arrayLikeToArray(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=Array(e);n<e;n++)t[n]=r[n];return t}(()=>{function r(i,u,t){return{flatTree:function n(r,e,t){var o=e||0;e=t||[];if(15<o)throw new Error("Exceeded maximum level of nesting");return _.reduce(r,function(r,e){return e._depth=o,r.push(e),n(e._subGroups,o+1,r)},e)},copyUserRoles:function(r,o,a,e){var n=i.when();e=e?(n=i.all(_.map(o,function(r){return u.removeInventoryRoles(a,r.id)})),function(){return i.all(_.map(r,function(r){var e=_.map(r.roles,function(r){return{id:r.id}});return u.assignInventoryRoles(a,r.managedObject,e)}))}):function(){return i.all(_.map(r,function(r){var e=r.managedObject,n=_.find(o,{managedObject:e}),t=_.get(n,"roles"),n=_.get(n,"id"),r=_(_.union(r.roles,t)).uniqBy("id").map(function(r){return{id:r.id}}).value(),t=n?u.updateInventoryRoles(a,n,r):u.assignInventoryRoles(a,e,r);return t}))};return n.then(e)},onSaveInventoryRoles:function(o,a){var r=_.filter(a,"isModified").map(function(r){var e,n=o,t=a;return(t=(t[r.managedObject]||{}).id)?e=r.roles.length?u.updateInventoryRoles(n,t,r.roles):u.removeInventoryRoles(n,t):r.roles.length&&(e=u.assignInventoryRoles(n,r.managedObject,r.roles)),e||i.when()});return i.all(r)},listRootGroups:function(){var r=(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).onlyRootsUser,r={query:"$filter=(".concat("has('c8y_IsDeviceGroup')",")$orderby=name"),onlyRoots:!0,onlyRootsUser:r,withChildren:!1};return t.listAll(r)},loadChildren:l,expandAll:function(r,e){function n(){var r;o<=5&&((r=a.shift())?(o++,l(r).then(function(r){e&&e(),a.push.apply(a,_toConsumableArray(r)),o--,n()},t.reject),n()):0===o&&t.resolve())}var t=i.defer(),o=0,a=Array.from(r);return n(),t.promise}};function l(e){var r={query:"$filter=((has('c8y_IsDeviceGroup')) and bygroupid(".concat(e.id,"))"),pageSize:2e3,withChildren:!1,withTotalPages:!1},n=[].concat(_toConsumableArray(e._parentGroups||[]),[e]);return t.list(r).then(function(r){return r.forEach(function(r){r._parentGroups=Array.from(n)}),e._subGroups=_.sortBy(r,"name"),e._subGroups})}}r.$inject=["$q","c8yUser","c8yInventory"],angular.module("c8y.userRoles").factory("c8yUserInventoryRoles",r)})();