(()=>{function e(e,i,r,t,a,c,u,p,n,d,s,l){var g=10,o=2e3,v=1950;return{loadAll:function(){(()=>{var e={name:"Groups",icon:"c8y-group",iconOpen:"c8y-group-open",sortAlphabetically:!0,path:"group",hasChildren:!0};e.priority=G(),t.addNavigation(e)})(),a.getTopLevelGroups(N()).then(A),e.$on("c8yInventory:update",m)},addGroupNavigation:C,updateGroupNavigation:D,removeGroupNavigation:function(e){e=t.findNode(I(e));t.removeNavigation(e)},updateGroupChildren:x,updateAllGroupsOfAChild:function(e){e=l.extractParents(e);_.forEach(e,function(e){x(e)})},getIconSpecsForType:function(e){return a.getIconSpecsForType(e)},getNav:S};function f(n){var e,o;n.loading||(e=n.group_id,o=i.when([]),n.loading=!0,n.is_group&&(o=a.getGroupAssetsAndDevices(e)),(o=n.is_dynamicGroup?p.getGroupItems(e,{pageSize:g}):o).then(function(e){return h(n,e,!0)}))}function h(n,e,o){o&&n.removeAllChildren(),n.loading=!1;o=_.map(e,function(e){e=S(e,n.is_device);return e.parent=n.hash,e.sortAlphabetically=!0,e}),o=t.addNavigation(o);_.forEach(o,function(e){e.is_device?e.on("active",function(){u.setPreferredBreadcrumb({id:e._parent.group_id})}):e.on("expand",f).on("collapse",y)}),n.showMore=e.paging&&e.paging.next&&function(){return e.paging.next().then(_.partial(h,n))}}function y(e){e.removeAllChildren()}function m(e,n){var n=n.mo,o=(l.detail(n,{withParents:!0}).then(function(e){return e.data}).then(D),_.get(r,"deviceId")||_.get(r,"groupId"));_.isUndefined(o)||n.id!==o||s.changeTitle({title:n.name},{skipTitleTranslation:!0})}function G(){return N()?o:v}function N(){return"devicemanagement"===n.getCurrentContextPath()}function A(e){e.forEach(C)}function C(e){e=S(e);e.parent="Groups",t.addNavigation(e).on("expand",f).on("collapse",y)}function D(e){var n=t.findNode(I(e));n&&n.update(S(e))}function x(e){e=t.findNode(I(e));e&&(e.collapse(),e.expand())}function I(n){return function(e){return e.group_id===n.id}}function S(e){var n=a.getGroupInfo(e),o=c.isDeviceOrChildDevice(e),o={group_id:e.id,closed:!0,hasChildren:!0,is_device:o,is_group:n.isGroup,is_dynamicGroup:n.isDynamicGroup,hasBrokerSource:n.hasBrokerSource,device:o?e:void 0,name:o?c.properName(e):e.name,priority:G(),path:"".concat(n.isGroup||n.isDynamicGroup?"group":"device","/").concat(e.id),sortAlphabetically:!n.isDynamicGroup,showMoreLabel:n.isDynamicGroup?d("Search more"):void 0};return _.assign(o,n.iconSpecs),o}}e.$inject=["$rootScope","$q","$routeParams","c8yNavigator","c8yGroups","c8yDevices","c8yBreadcrumbs","c8yDynamicGroups","c8yApplication","gettext","c8yTitle","c8yInventory"],angular.module("c8y.ui").factory("groupTypesHierarchyNavigator",e)})();