(()=>{function e(t,i,c,n,s,a,d,u,o,l){function r(e){t.device=e.device,t.devices={},t.variables=[],t.devices[e.device.id]=e.device,_.forEach(e.children,function(e){t.devices[e.id]=e}),t.variables.push(t.device),t.variables.push(t.devices)}function v(){t.reloading=!0;var e,i=y("devices");return y("device")||i?(e=t.child.config.device.id,i=i,d.all({device:s.detail(e).then(u.getResData),children:i?c.listChildren(e):[]}).then(r).then(function(){t.reloading=!1})):(t.reloading=!1,d.when())}function h(e,i){var c;!t.reloading&&t.device&&(t.device.id===i.id?(c=i,_.isEqual(c.childDevices,t.device.childDevices)&&_.isEqual(c.childAssets,t.device.childAssets)?(t.device=c,t.devices[c.id]=c):v()):(c=i,t.devices[c.id]&&(t.devices[c.id]=c)))}function f(e){return"/managedobjects/".concat(e)}function g(e){o.addListener(t.$id,f(e),o.realtimeActions().UPDATE,h),o.start(t.$id,f(e))}function p(){t.devices&&Object.keys(t.devices).forEach(function(e){o.stop(t.$id,f(e))}),t.device=null,t.devices=null}function y(e){var e=e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1"),i=new RegExp("\\{\\{[^\\}]*\\b".concat(e,"\\b[^\\}]*}}")),e=new RegExp('ng[\\w-]*="[^"]*\\b'.concat(e,'\\b[^"]*'));return i.test(t.child.config.html)||e.test(t.child.config.html)}function C(){var e=[];t.countersLoaded=!1,y("devicesCount")&&e.push(l.getSummary().then(function(e){t.devicesCount=e.data.deviceWithChildrenCount,t.variables.push(t.devicesCount)})),y("deviceGroupsCount")&&e.push(s.getCount({fragmentType:"c8y_IsDeviceGroup"}).then(function(e){t.deviceGroupsCount=e,t.variables.push(t.deviceGroupsCount)})),y("usersCount")&&e.push(a.mustHaveAnyRole(["ROLE_USER_MANAGEMENT_READ"]).then(i.list).then(function(e){t.usersCount=e.length,t.variables.push(t.usersCount)})),y("criticalDevicesCount")&&e.push(s.list({fragmentType:"c8y_ActiveAlarmsStatus"}).then(function(e){t.criticalDevicesCount=_.filter(e,function(e){return e.c8y_ActiveAlarmsStatus&&e.c8y_ActiveAlarmsStatus.critical}).length,t.variables.push(t.criticalDevicesCount)})),y("onlineCount")&&e.push(c.list({pageSize:1e3}).then(function(e){t.onlineCount=_.filter(e,function(e){return n.isDeviceAvailable(e)}).length})),d.all(e).then(function(){t.countersLoaded=!0}),p(),v().then(function(){t.devices&&Object.keys(t.devices).forEach(g)})}_.assign(this,{isVariableUsed:y}),t.$watch("child.config.device",function(e,i){e&&!_.isEqual(e,i)&&C()},!0),t.$watch("child.config.html",function(e,i){void 0===e||_.isEqual(e,i)||C()}),t.$on("$destroy",p),t.variables=[],C()}e.$inject=["$scope","c8yUser","c8yDevices","c8yDeviceStatus","c8yInventory","c8yPermissions","$q","c8yBase","c8yRealtime","c8yStatistics"],angular.module("c8y.parts.htmlwidget").controller("HtmlWidgetCtrl",e)})();