function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_unsupportedIterableToArray(e,t)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var r;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(r="Object"===(r={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:r)||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function _iterableToArrayLimit(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,i,o,l=[],c=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(l.push(n.value),l.length!==t);c=!0);}catch(e){u=!0,a=e}finally{try{if(!c&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(u)throw a}}return l}}function _arrayWithHoles(e){if(Array.isArray(e))return e}(()=>{function e(l,c,u,s,i,t,m){var n=u.createEnum([{name:"ALARM",value:"ALARM",label:m("Alarm")},{name:"EVENT",value:"EVENT",label:m("Event")}]);return{TIMELINE_TYPES:n,getSampleAlarmsAndEventsConfigsForDevice:function(e){return l.all([(e=>(e={source:e.id||e,pageSize:10},s.list(e).then(function(e){return _.map(e,function(e){return{__active:!1,__target:_.pick(e.source,"id","name"),label:e.type,color:t.generateColor(),timelineType:n.ALARM.value,filters:{type:e.type}}})})))(e),(e=>(e={source:e.id||e,pageSize:10},i.list(e).then(function(e){return _.map(e,function(e){return{__active:!1,__target:_.pick(e.source,"id","name"),label:e.type,color:t.generateColor(),timelineType:n.EVENT.value,filters:{type:e.type}}})})))(e)]).then(_.flatten).then(r)},getEmptyAlarmEventConfigForDevice:function(e){return{__active:!1,__target:_.pick(e,"id","name"),label:"",color:t.generateColor(),timelineType:n.ALARM.value,filters:{type:""}}},fetchTimelinesForAlarmsEvents:function(e,r){e=_.filter(e,{__active:!0}),e=_.map(e,function(t){return((e,t)=>{var r=l.when([]),t=_.assign({},t,e.filters,{source:e.__target.id});return e.timelineType===n.EVENT.value?r=(e=>i.list(e).then(function(e){return l.all(_.map(e,o))}))(t):e.timelineType===n.ALARM.value&&(r=(e=>{var t=_.assign({},e,{dateFrom:moment(0).format(u.dateFullFormat),dateTo:e.dateFrom,revert:!0,pageSize:1}),r=e,e=_.assign({},e,{dateFrom:e.dateTo,dateTo:moment().format(u.dateFullFormat),pageSize:1}),t=[s.list(t),s.list(r),s.list(e)];return l.all(t).then(_.flatten).then(function(e){return l.all(_.map(e,a))})})(t)),r})(t,r).then(function(e){return{label:t.label,color:t.color,events:e,alarmsEventsConfig:t}})});return l.all(e)},alarmMatchesConfig:function(e,t){return _.isMatch(t,{timelineType:"ALARM",__target:{id:e.source.id},filters:{type:e.type}})},eventMatchesConfig:function(e,t){return _.isMatch(t,{timelineType:"EVENT",__target:{id:e.source.id},filters:{type:e.type}})},transformAlarmToTimelineEvent:a,transformEventToTimelineEvent:o};function r(e){return _.uniqBy(e,function(e){return[e.__target.id,e.timelineType,e.filters.type].join(":")})}function a(n){return l.all([s.alarmDurationDiff(n),(r=n,a=c("absoluteDate"),i=c("translate"),o=c("humanize2"),s.statusText(r).then(function(e){var t=r.firstOccurrenceTime||r.time;return _.flatten(['<i class="dlt-c8y-icon-bell"></i> <b>'.concat(a(t),"</b>"),"".concat(i(m("Status")),": ").concat(e),_.map(s.getStandardKeys(r,["lastUpdated"]),function(e,t){return"".concat(_.escape(i(e)),": <b>").concat(_.escape(r[t]),"</b>")}),"".concat(i(m("Last updated")),": <b>").concat(a(r.lastUpdated),"</b>"),_.map(s.getNonStandardKeys(r),function(e){return"".concat(_.escape(o(e)),": <b>").concat(_.escape(JSON.stringify(r[e])),"</b>")})]).join("<br />")}))]).then(function(e){var e=_slicedToArray(e,2),t=e[0],e=e[1],r=n.firstOccurrenceTime||n.time||n.creationTime,t=n.status===s.status.CLEARED&&t?moment(r).subtract(t).format(u.dateFullFormat):void 0;return{id:n.id,dateFrom:r,dateTo:t,tooltip:e}});var r,a,i,o}function o(t){return r=t,e=c("absoluteDate"),n=c("translate"),a=c("humanize2"),l.when(_.flatten(['<i class="dlt-c8y-icon-rss"></i> <b>'.concat(e(r.time),"</b>"),_.map(i.getStandardKeys(r),function(e,t){return"".concat(_.escape(n(e)),": <b>").concat(_.escape(r[t]),"</b>")}),_.map(i.getNonStandardKeys(r),function(e){return"".concat(_.escape(a(e)),": <b>").concat(_.escape(JSON.stringify(r[e])),"</b>")})]).join("<br />")).then(function(e){return{id:t.id,date:t.time,tooltip:e}});var r,e,n,a}}e.$inject=["$q","$filter","c8yBase","c8yAlarms","c8yEvents","c8yUiUtil","gettext"],angular.module("c8y.alarmsEventsExplorer").factory("c8yAlarmsEventsTimelinesChartService",e)})();