function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_unsupportedIterableToArray(t,e)||_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(t,e){var n;if(t)return"string"==typeof t?_arrayLikeToArray(t,e):"Map"===(n="Object"===(n={}.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:n)||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(t,e):void 0}function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function _iterableToArrayLimit(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,a,i,o,s=[],l=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=i.call(n)).done)&&(s.push(r.value),s.length!==e);l=!0);}catch(t){u=!0,a=t}finally{try{if(!l&&null!=n.return&&(o=n.return(),Object(o)!==o))return}finally{if(u)throw a}}return s}}function _arrayWithHoles(t){if(Array.isArray(t))return t}(t=>{var l=[{id:"minutes",txt:t("Last minute"),unit:"minutes",qty:1},{id:"hours",txt:t("Last hour"),unit:"hours",qty:1},{id:"days",txt:t("Last day"),unit:"days",qty:1},{id:"weeks",txt:t("Last week"),unit:"weeks",qty:1},{id:"months",txt:t("Last month"),unit:"months",qty:1},{id:"custom",txt:t("Custom"),unit:!1}],u=_.last(l),t=_.reduce(l,function(t,e){return e.qty&&(t[e.id]=moment.duration(e.qty,e.unit)),t},{});angular.module("c8y.ui").directive("c8yInterval",["$parse",function(a){return{restrict:"E",template:'\n        <div class="c8y-select-wrapper"><select\n          class="form-control"\n          title="{{\'Interval\' | translate}}"\n          aria-label="{{\'Interval\' | translate}}"\n          ng-options="interval.id as (interval.txt | translate) for interval in __intervals"\n          ng-model="__selected"\n          ng-change="__onChange()"\n          ng-model-options="{debounce: 150}" >\n        </select><span></span></div>',replace:!0,scope:!0,link:function(i,t,e){var o={},n=a(e.dateFrom),r=a(e.dateTo),s=a(e.interval),e=(i.__selected=u.id,i.__intervals=l,i.__onChange=function(){var t,e;s.assign&&s.assign(i,i.__selected),i.__selected!==u.id&&(t=_.find(l,function(t){return t.id===i.__selected}),e=moment(),t)&&t.qty&&(o.dateFrom=moment(e).subtract(t.qty,t.unit).toDate(),o.dateTo=e.toDate(),n.assign(i,o.dateFrom),r.assign(i,o.dateTo))},"[".concat([e.dateFrom,e.dateTo,e.interval,e.realtime].join(","),"]"));i.$watch(e,function(t,e){var n=_slicedToArray(t,3),r=n[0],a=n[1],n=n[2];o.dateFrom||o.dateTo||!s.assign||(i.__selected=n||u.id),t!==e&&(t={dateFrom:r,dateTo:a},((e=o).dateFrom&&new Date(e.dateFrom).getTime())===(t.dateFrom&&new Date(t.dateFrom).getTime())&&(e.dateTo&&new Date(e.dateTo).getTime())===(t.dateTo&&new Date(t.dateTo).getTime())||(n!==u.id&&(i.__selected=((e,n)=>{var t;return!(1e4<Math.abs(moment(n).diff(moment())))&&(t=_(l).filter(function(t){return t.unit}).find(function(t){return moment(n).subtract(t.qty,t.unit).isSame(e,"second")}))&&t.id||u.id})(r,a)),!s.assign)||s.assign(i,i.__selected))},!0)}}}]).constant("INTERVAL_CONSTANTS",{intervals:l,durations:t,custom:_.last(l),_defaultDuration:"hours"})})(_.identity);