(()=>{function e(e,n,t,r,u){var c=["#AF81C9","#F89A7E","#F2CA85","#54D1F1","#7C71AD","#445569"],i={};function a(e){return e.data.c8y_Kpi||[]}function o(e,n){var t=n[e.fragment]||{};return t.kpi=e,t.time=n.time,t.source=n.source,t}function s(){return e.deviceId}function f(e){return n.detail(e||s()).then(a)}function p(n,t,e){i=e;var r,u,i,a={fragment:r=n,series:u=t,label:((e,n)=>"".concat(g(e)," => ").concat(g(n)))(r,u),min:0,max:100,color:(e=>{var n=0;return _.forEach(e,function(e){n<c.length&&e.color.toLowerCase()===c[n].toLowerCase()&&n++}),c[n]||"#FFFFFF"})(i)};return _.forEach(e,function(e){e.fragment===n&&e.series===t&&(a=e)}),a}function g(e){return(e||"").replace("c8y_","").replace(/[A-Z]/g," $&").replace(/^\s/,"")}function m(e){return n.update({id:s(),c8y_Kpi:e})}function l(n){return t.list({fragmentType:n,source:s(),pageSize:1,dateFrom:null,dateTo:null}).then(function(e){return e[0]||{}}).then(function(e){return e[n]})}return{list:f,getKpi:function(e,n){return f().then(angular.bind({},p,e,n))},updateKpi:function(u){return f().then(function(t){var r=!1;return _.forEach(t,function(e,n){e.fragment===u.fragment&&e.series===u.series&&(t[n]=_.cloneDeep(u),r=!0)}),r||t.push(u),t}).then(m)},update:m,getMeasurement:function(e){return t.list(_.assign(u.timeOrderFilter(),{revert:!0,fragmentType:e.fragment,source:s(),reverse:!0,pageSize:1})).then(function(e){return e[0]||{}}).then(angular.bind({},o,e))},hasSupportedMeasurements:function(){var e=i[s()]||r.getSupportedMeasurements(s()).then(function(e){return 0<e.length});return i[s()]=e},getSupportedMeasurements:function(){return r.getSupportedMeasurements(s())},getSupportedSeries:l,getOneSeries:function(e,n){return l(e).then(function(e){return e[n]})},getHumanizedName:g,getKpiFromList:p}}e.$inject=["$routeParams","c8yInventory","c8yMeasurements","c8yDevices","c8yBase"],angular.module("c8y.parts.kpi").factory("kpiSvc",e)})();