(()=>{var u;function e(e){u={},e.register("lastMeasurement",t,{configTemplateUrl:":::PLUGIN_PATH:::/ui/properties/lastMeasurementConfig.html"})}function t(e,a){var e=e||{},t=_.isArray(e.dp)?_.find(e.dp,"__active")||_.last(e.dp):{},r=e.target||t.__target,n=e.fragment||t.fragment,i=e.series||t.series,c=e.resultType||a.RESULT_TYPES.VALUE.value;return s.detach=function(e){var t=_.get(u,e.id);t&&t.detach(e)&&delete u[e.id]},s;function s(e){u[e.id]=u[e.id]||new a.Updater(e);var t=u[e.id];return t.attach(e),t.resultType=c,t.get(n,i,r)}}function a(e,u,n,t,c){var s=e.createEnum([{name:"VALUE",value:1,label:t("Only value")},{name:"VALUE_UNIT",value:2,label:t("Value and unit")},{name:"VALUE_UNIT_TIME",value:3,label:t("Value, unit and time")},{name:"OBJECT",value:4,label:t("Complete object")}]);function a(e){var t=this;t.device=e,t.cache={},t.devices=new Set,t.attach(e),t.latestPromises=[]}return a.prototype.attach=function(e){var t=this.devices;t.has(e)||t.add(e)},a.prototype.detach=function(e){var t=this.devices;return t.delete(e),!t.size&&(_.forEach(this.latestPromises,function(e){return e.stop()}),!0)},a.prototype.lastMeasurementFilter=function(e,t,a){var r=this;return{device:n.isProbablyDevice(r.device)||n.isAsset(r.device)?r.device.id:_.get(a,"id",r.device.id),fragment:e,series:t}},a.prototype.format=function(e,t){var a=e.value,r=e.unit,n=t.time,i="";switch(this.resultType||s.VALUE.value){case s.VALUE.value:i=a;break;case s.VALUE_UNIT.value:i=a+(r||"");break;case s.VALUE_UNIT_TIME.value:i="".concat(c("absoluteDateShort")(n)," | ").concat(a+(r||""));break;default:s.OBJECT.value;i=e}return i},a.prototype.get=function(e,t,a){var r=this,n=this,i="".concat(e,".").concat(t),c="loading".concat(i),s="",a=(n.cache[i]||n[c]||(n[c]=!0,a=u.latest(n.lastMeasurementFilter(e,t,a),!0),this.latestPromises.push(a),a.then(function(e){r.cache[i]=e}).finally(function(){return delete r[c]})),_.get(n.cache,i,{})),e=_.get(a,"".concat(e,".").concat(t));return s=e?n.format(e,a):s},{RESULT_TYPES:s,Updater:a}}t.$inject=["config","lastMeasurementComputedProperty"],a.$inject=["c8yBase","c8yMeasurements","c8yDevices","gettext","$filter"],e.$inject=["c8yComputedPropertiesProvider"],angular.module("c8y.ui").config(e).factory("lastMeasurementComputedProperty",a)})();