(()=>{function e(a,e,n){var i,e=e.deviceId,t=[{value:void 0,name:"No aggregation"},{value:"HOURLY",name:"Hourly"},{value:"DAILY",name:"Daily"}],o=[{timeIntervalValue:"minutes",aggregationType:void 0},{timeIntervalValue:"hours",aggregationType:void 0},{timeIntervalValue:"days",aggregationType:"HOURLY"},{timeIntervalValue:"weeks",aggregationType:"HOURLY"},{timeIntervalValue:"months",aggregationType:"DAILY"}];function r(){a.config.kpis=_.map(_.filter(a.kpis,"selected"),function(e){return _.assign({moId:e.id},e.c8y_Kpi)})}function g(e){i&&i(),n.listKpiForDevice(e).then(function(e){var n;a.kpis=e.matchKpi||[],a.kpisByFragment=_.groupBy(a.kpis,function(e){return e.c8y_Kpi.fragment}),a.measurements=e.nonKpiSeries,a.measurementsByFragment=_.groupBy(e.nonKpiSeries,"fragment"),a.allMeasurements=_.sortBy(_.union(_.map(a.measurements,"fragment"),_.map(a.kpis,function(e){return e.c8y_Kpi.fragment}))),n=a.config.kpis,_.forEach(a.kpis,function(e){e.selected=!!_.find(n,{moId:e.id})}),i=a.$watch(function(){return _.map(_.filter(a.kpis,"selected"),"id").join("::")},r)})}a.selectdKpis={},a.deviceId=e,a.timeIntervals=[{value:"minutes",name:"Last minute"},{value:"hours",name:"Last hour"},{value:"days",name:"Last day"},{value:"weeks",name:"Last week"},{value:"months",name:"Last month"}],a.aggregationTypes=t,a.onAggregationTypeChangedManually=function(){a.config.aggregationTypeChangedManually=!0},a.$watch("config.device",function(e){e&&g(e.id)}),a.$watch("config.timeInterval",function(n){!a.config.aggregationTypeChangedManually&&n&&_.forEach(o,function(e){n===e.timeIntervalValue&&(a.config.aggregationType=e.aggregationType)})})}e.$inject=["$scope","$routeParams","c8yKpi"],angular.module("c8y.parts.kpi").controller("MultipleKpiConfigCtrl",e)})();