(()=>{function e(e,n,t){var a=this,i=[],o=2,m={dateFrom:void 0,dateTo:void 0,timelines:[]},r=_.throttle(function(e,n,t){_.assign(a.timeline,{dateFrom:_.clone(e),dateTo:_.clone(n),timelines:t})},300);function l(){e.$broadcast("c8yTimelinesChart::render")}function s(e,n){var t;return t=n,!((!_.isUndefined(e)||_.isUndefined(t))&&(t=n,_.isUndefined(e)&&_.isUndefined(t)||(t=moment(n).diff(e,"seconds"),a.realtime)||t<o))}function d(){var e={dateFrom:moment(a.dateFrom).format(n.dateFullFormat),dateTo:moment(a.dateTo).format(n.dateFullFormat),withTotalPages:!0,pageSize:1e3};t.fetchTimelinesForAlarmsEvents(i,e).then(function(e){r(a.dateFrom,a.dateTo,e)})}function c(e){_.forEach(i,function(n){t.alarmMatchesConfig(e,n)&&t.transformAlarmToTimelineEvent(e).then(function(e){return u(e,n)})})}function f(e){_.forEach(i,function(n){t.eventMatchesConfig(e,n)&&t.transformEventToTimelineEvent(e).then(function(e){return u(e,n)})})}function u(e,n){var n=_.findIndex(a.timeline.timelines,{alarmsEventsConfig:n}),n=a.timeline.timelines[n].events,t=_.findIndex(n,{id:e.id});-1===t?n.push(e):n[t]=e}_.assign(a,{$onInit:function(){a.onRealtimeAlarmFn({onRealtimeAlarm:c}),a.onRealtimeEventFn({onRealtimeEvent:f})},$onChanges:function(e){var n=!1;e.alarmsEventsConfigs&&(i=_.cloneDeep(a.alarmsEventsConfigs));e.dateFrom&&(n=s(a.timeline.dateFrom,e.dateFrom.currentValue),a.timeline.dateFrom=_.clone(e.dateFrom.currentValue));e.dateTo&&(n=s(a.timeline.dateTo,e.dateTo.currentValue),a.timeline.dateTo=_.clone(e.dateTo.currentValue));e.chartBox&&(a.timeline.chartBox=_.clone(e.chartBox.currentValue));e.realtime&&!1===_.get(e,"realtime.previousValue")&&(n=!0);(n?d:l)()},$doCheck:function(){var e=!1;_.isEqual(i,a.alarmsEventsConfigs)||(i=_.cloneDeep(a.alarmsEventsConfigs),e=!0);moment(a.timeline.dateFrom).isSame(a.dateFrom)||(e=s(a.timeline.dateFrom,a.dateFrom),a.timeline.dateFrom=_.clone(a.dateFrom));moment(a.timeline.dateTo).isSame(a.dateTo)||(e=s(a.timeline.dateTo,a.dateTo),a.timeline.dateTo=_.clone(a.dateTo));_.isEqual(a.dateFrom,a.dateTo)&&(e=!1);(e?d:l)()},timeline:m})}e.$inject=["$scope","c8yBase","c8yAlarmsEventsTimelinesChartService"],angular.module("c8y.alarmsEventsExplorer").component("c8yAlarmsEventsTimelinesChart",{bindings:{alarmsEventsConfigs:"<",dateFrom:"<",dateTo:"<",realtime:"<",chartBox:"<",onRealtimeAlarmFn:"&?",onRealtimeEventFn:"&?",onUpdateDates:"&",onSizeChanged:"&"},templateUrl:":::PLUGIN_PATH:::/alarmsEventsTimelinesChart/alarmsEventsTimelinesChart.html",controller:e,controllerAs:"vm"})})();