(()=>{function e(o,i,c,t,n,e,s,a,r,d,l,u,f){function m(e){o.counters={},_.forEach(e,function(i){o.counters[i.id]={},_.forEach(_.filter(l,g),function(e){var t,n;t=i,e=e,n=o.counters[t.id],t=e.counter({dateFrom:e.dateFrom,type:o.options.data[e.name].type,source:t.id}),(n[e.name]=t).onNotification(function(){o.realtimeAnimation=!0}),t.start()})}),o.devices=e}function v(e){_.forEach(e,function(n){_.forEach(l,function(e){var t=n;(t=o.counters[t.id][e.name])&&t.stop()})})}function g(e){return!!o.options.data[e.name]}function p(e){o.devices&&v(o.devices),o.options=e,e=o.options.assets,e=_.map(e,"id").join(","),t.list({ids:e}).then(m)}function h(e){return d.checkIfModulesExist(["c8y.deviceDetailControl","c8y.parts.deviceControlList"])?f.getString('To see the result click <a href="#/device/{{deviceId}}/control">here</a>',{deviceId:e}):""}o.counterColumns=l,o.realtimeChannel="/managedobjects/*",o.lastValidMessageIcon=n.lastValidMessageIcon,o.lastValidMessageColor=n.lastValidMessageColor,o.lastValidMessageTooltip=n.lastValidMessageTooltip,o.orderBy=function(e){o.devices=i("orderBy")(o.devices,e)},o.getIcon=function(e,n,i){var t;return e?(t=e,e=_.find(o.options.iconsMap,function(e){return e.id===t}),_.find(e.map,function(e){return s.compare(e.comparison,e.value.toLowerCase(),(e={obj:e=i},t=c("obj.".concat(t=n))(e),_.isObjectLike(t)&&(t=angular.toJson(t)),String(t).toLowerCase()));var t})):{icon:"question-circle-o",color:"red"}},o.switchMaintenance=function(e){n.switchResponseInterval(e)},o.orderAlarms=function(e){o.devices=_.sortBy(o.devices,function(e){e=e.c8y_ActiveAlarmsStatus||{};return[e.critical,e.major,e.minor,e.warning]}),e&&o.devices.reverse()},o.orderLastValidMessage=function(e){o.devices=_.sortBy(o.devices,function(e){return n.isLastValidMessage(e)}),e&&o.devices.reverse()},o.orderByCount=function(e,t){var n=_.map(o.devices,function(e){return _.assign({},e,{counter:o.counters[e.id]})}),n=i("orderBy")(n,"counter.".concat(e,".count"),t);o.devices=_.map(n,function(e){return delete e.counter,e})},o.executeOperation=function(t,n){var i=_.cloneDeep(t.json);i.deviceId=n,t.isPending=t.isPending||{},a.createWithNotifications(i).then(function(e){t.isPending[n]=!0,e.created.then(function(){return r.success(f.getString('"{{description | translate}}" will be executed.',i))}),e.completed.then(function(e){t.isPending[n]=!1,e.status===a.status.SUCCESSFUL?r.info("".concat(f.getString('"{{description | translate}}" completed.',i)," ").concat(h(n))):e.status===a.status.FAILED&&r.danger("".concat(f.getString("{{description | translate}} failed.",i)," ").concat(h(n)))})})},o.statusIcon=n.statusIcon,o.statusClass=n.statusClass,o.tooltip=_.memoize(n.availabilityTooltip,function(e){return e.id}),o.$watch("child.config.options",function(e,t){e&&!_.isEqual(e,t)&&p(e)}),e.addListener(o.$id,o.realtimeChannel,"".concat(o.$id,"-subscribed"),function(){o.realtimeAnimation=!1,p(o.child.config.options)}),e.addListener(o.$id,o.realtimeChannel,e.realtimeActions().UPDATE,function(e,t){for(var n in o.realtimeAnimation=!0,o.devices)o.devices[n].id===t.id&&(o.devices[n]=t)}),e.switchRealtime(o.$id,o.realtimeChannel)}e.$inject=["$scope","$filter","$parse","c8yInventory","c8yDevices","c8yRealtime","c8yComparisons","c8yDeviceControl","c8yAlert","c8yBase","counterColumns","gettext","gettextCatalog"],angular.module("c8y.assets").controller("AssetsCtrl",e)})();