function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ownKeys(t,e){var r,i=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),i.push.apply(i,r)),i}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(r),!0).forEach(function(e){_defineProperty(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function _defineProperty(e,t,r){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _toPropertyKey(e){e=_toPrimitive(e,"string");return"symbol"==_typeof(e)?e:e+""}function _toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0===r)return("string"===t?String:Number)(e);r=r.call(e,t||"default");if("object"!=_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(()=>{function e(e){e.register("lastDeviceMessage",t)}function t(n,o,c,a,s,p,t){var r={};function u(e){return t.list({source:e,pageSize:50})}function d(e,t){var r=this;r.device=e,r.service=t.service,r.check_audit=t.check_audit,r.rt_channel="/".concat(t.rt_channel,"/").concat(e.id),r.filter_prop=t.filter_prop||"source",r.time_prop=t.time_prop||"time",r.ops=t.ops,r.list(t.listFilters).then(_.bind(r.onList,r))}function i(t){var r,e,i=this;i.device=t,i.dateObj=[(r=i,e={},Object.defineProperty(e,"timestamp",{get:function(){var e=r.device||{};return e.c8y_Availability&&e.c8y_Availability.lastMessage}}),e)],i.devices=new Set,_.forEach([{service:o,rt_channel:"alarms",check_audit:!0},{service:c,rt_channel:"events",ops:["CREATE"],time_prop:"creationTime"},{service:a,rt_channel:"measurements",ops:["CREATE"],listFilters:{revert:!0}},{service:s,rt_channel:"operations",ops:["UPDATE"],filter_prop:"deviceId",check_audit:!0,listFilters:{dateFrom:new Date(0).toISOString(),dateTo:new Date(Date.now()).toISOString(),revert:!0}}],function(e){e=new d(t,e);i.dateObj.push(e)})}function e(e){r[e.id]=r[e.id]||new i(e);var t=r[e.id];return t.device=e,t.add(e),t.get()}return d.prototype.list=function(){var e=this,t=_objectSpread({pageSize:1},0<arguments.length&&void 0!==arguments[0]?arguments[0]:{});return t[e.filter_prop]=e.device.id,e.service.list(t)},d.prototype.updateValue=function(e){var t=this;t.timestamp||(t.timestamp=e),moment(t.timestamp).isBefore(e)&&(t.timestamp=e)},d.prototype.onList=function(e){var t=this,e=_(e),r=t.check_audit?"id":t.time_prop,i=_.bind(t.updateValue,t),i=t.check_audit?function(e){u(e).then(_.bind(t.onAudit,t))}:i;e.map(r).forEach(i),t.startRealtime()},d.prototype.onRealtime=function(e,t){var r=this;r.check_audit?u(t.id).then(_.bind(r.onAudit,r)):r.updateValue(t[r.time_prop])},d.prototype.onAudit=function(e){_(e).filter(_.bind(this.byOwner,this)).map("creationTime").forEach(_.bind(this.updateValue,this))},d.prototype.byOwner=function(e){var t=this.device;return e.user===t.owner},d.prototype.startRealtime=function(){var t=this,r=(p.createLocalId(t,"rtId"),t.rtId),i=t.rt_channel,e=t.ops||["CREATE","UPDATE","DELETE"];_.forEach(e,function(e){n.addListener(r,i,e,_.bind(t.onRealtime,t))}),n.start(r,i)},d.prototype.stopRealtime=function(){n.removeSubscriber(this.rtId,this.rt_channel)},i.prototype.detach=function(e){var t=this.devices;t.delete(e),t.size||(_(this.dateObj).filter("stopRealtime").forEach(function(e){return e.stopRealtime()}),delete r[e.id])},i.prototype.add=function(e){this.devices.has(e)||this.devices.add(e)},i.prototype.get=function(){var e=_.map(this.dateObj,"timestamp");return(e=_(e).map(function(e){return e&&moment(e)}).filter(_.identity).value()).length?moment.max(e).format("YYYY-MM-DDTHH:mm:ssZ"):void 0},e.detach=function(e){var t=r[e.id];t&&t.detach(e)},e}t.$inject=["c8yRealtime","c8yAlarms","c8yEvents","c8yMeasurements","c8yDeviceControl","c8yBase","c8yAudits"],e.$inject=["c8yComputedPropertiesProvider"],angular.module("c8y.ui").config(e)})();