function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _toPropertyKey(e){e=_toPrimitive(e,"string");return"symbol"==_typeof(e)?e:e+""}function _toPrimitive(e,r){if("object"!=_typeof(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0===t)return("string"===r?String:Number)(e);t=t.call(e,r||"default");if("object"!=_typeof(t))return t;throw new TypeError("@@toPrimitive must return a primitive value.")}function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_unsupportedIterableToArray(e,r)||_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,r){var t;if(e)return"string"==typeof e?_arrayLikeToArray(e,r):"Map"===(t="Object"===(t={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:t)||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function _iterableToArrayLimit(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,i,o,a,l=[],u=!0,p=!1;try{if(o=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;u=!1}else for(;!(u=(n=o.call(t)).done)&&(l.push(n.value),l.length!==r);u=!0);}catch(e){p=!0,i=e}finally{try{if(!u&&null!=t.return&&(a=t.return(),Object(a)!==a))return}finally{if(p)throw i}}return l}}function _arrayWithHoles(e){if(Array.isArray(e))return e}angular.module("c8y.smartRules").directive("smartRuleParamInputKpi",function(){return{require:"^smartRuleParamInput",scope:{rule:"=",param:"=",ruleTemplate:"="},restrict:"E",templateUrl:":::PLUGIN_PATH:::/views/paramInputKpi.html",link:function(e,r,t,n){e.placeholder=n.placeholder},controller:["$scope","c8yKpi","c8yDatapointSelectorService",function(o,e,r){function t(){var e=o.param.property;e&&(o.kpiId=o.rule.config[e])}function i(e){var r=o.rule,t=o.param,r=r.config,n=_.find(o.kpis,{id:e}),i=t.mapSelectedKpiToProperties,i=(n&&i&&(n=n.c8y_Kpi,_.assign(r,_defineProperty(_defineProperty(_defineProperty(_defineProperty({},i.fragment,n.fragment),i.series,n.series),i.redRangeMin,_.get(n,"redRangeMin",90)),i.redRangeMax,_.get(n,"redRangeMax",100)))),t.property);i&&(r[i]=e)}_.assign(o,{getKpiLabel:function(e){e=e.c8y_Kpi;return"".concat(e.label," - ").concat(e.series)},openKpiSelector:function(){var n="thresholdSmartRule"===o.ruleTemplate.name;r.selectDataPoints({finishWithFirstSelection:!0,contextAsset:o.rule.c8y_Context?o.rule.c8y_Context.contextData:null,datapointTemplatesOnly:n,itemsEditable:!1}).then(function(e){var r,t,e=_slicedToArray(e,1)[0];n?(o.kpiId=e.__template,i(e.__template)):(e=e,r=o.rule,t=o.param,r=r.config,t=t.mapSelectedKpiToProperties,e&&t&&_.assign(r,_defineProperty(_defineProperty(_defineProperty(_defineProperty({},t.fragment,e.fragment),t.series,e.series),t.redRangeMin,_.get(e,"redRangeMin",90)),t.redRangeMax,_.get(e,"redRangeMax",100))))})},onKpiIdSelectionChange:i}),e.list().then(function(e){o.kpis=e}).then(t)}]}});