(()=>{n.$inject=["$parse","$timeout","gettext"],angular.module("c8y.ui").factory("c8yAggregationSvc",function(){return{calculate:y}}).directive("c8yAggregation",n);var v="NONE",a="MINUTELY",e="HOURLY",t="DAILY",g=moment.duration(10,"minute"),o=moment.duration(1,"day"),i=moment.duration(4,"days");function y(n){return i<=n?t:o<=n?e:g<n?a:v}function n(d,s,n){var _=[{value:v,name:n("None")},{value:a,name:n("Minutely")},{value:e,name:n("Hourly")},{value:t,name:n("Daily")}],f=!1;return{restrict:"E",template:'\n        <div class="c8y-select-wrapper"><select\n          class="form-control"\n          title="{{\'Aggregation\' | translate}}"\n          aria-label="{{\'Aggregation\' | translate}}"\n          ng-disabled="__realtime()"\n          ng-model="__aggregation"\n          ng-change="__onChange()">\n          <option\n            title="{{agg.name | translate}}"\n            ng-repeat="agg in __aggregations"\n            value="{{agg.value}}"\n            ng-disabled="__disabled[agg.value]">\n            {{agg.name | translate}}\n          </option>\n        </select><span></span></div>',replace:!0,scope:!0,link:function(t,n,g){function o(n){return void 0===n?v:n}function i(n){return n===v?void 0:n}var r=d(g.dateFrom),l=d(g.dateTo),u=d(g.aggregation),a=d(g.realtime),e=f||!!g.aggregateRealtime,m=(t.__aggregations=_,null),c=(t.__onChange=function(){m=moment.duration(moment(l(t)).diff(r(t))),u.assign(t,i(t.__aggregation))},t.__realtime=function(){return a(t)},"{\n        dateFrom: ".concat(g.dateFrom,",\n        dateTo: ").concat(g.dateTo,",\n        aggregation: ").concat(g.aggregation,",\n        realtime: ").concat(g.realtime,"\n      }"));t.$on("$destroy",function(){e&&(f=!1)}),t.$watch(c,function(n,a){var e;g.auto&&"false"!==g.auto&&(n.realtime&&!f?(t.__aggregation=o(),u.assign(t,i(t.__aggregation))):n===a||n.aggregation!==a.aggregation?t.__aggregation=o(n.aggregation):(a=y(e=moment.duration(moment(l(t)).diff(r(t)))))!==(m&&y(m))&&(m=null,s(function(){t.__disabled={DAILY:e<=moment.duration(1,"day"),HOURLY:e<=moment.duration(1,"hour"),MINUTELY:e<=moment.duration(1,"minute")}}),t.__aggregation=a,u.assign(t,i(a))))},!0)}}}})();