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 ownKeys(t,e){var n,r=Object.keys(t);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(t),e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)),r}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(n),!0).forEach(function(e){_defineProperty(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function _defineProperty(e,t,n){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _toPropertyKey(e){e=_toPrimitive(e,"string");return"symbol"==_typeof(e)?e:e+""}function _toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0===n)return("string"===t?String:Number)(e);n=n.call(e,t||"default");if("object"!=_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(()=>{function e(l,p,f,d,s,y){return{require:"ngModel",restrict:"EA",link:function(o,e,t,n){var r={},i=s.SHARED_CONTEXTS.COMPUTED_PROPERTY_LAST_MEASUREMENT.value;function c(e){return _.find(o.devices,{id:e})}function a(){n.$setViewValue(_.cloneDeep(o.mappings))}function u(e){var t=o.deviceIds,n=o.devices,r=t[e.placeholder];r&&_.find(n,{id:r})||(t[e.placeholder]=(_.head(n)||{}).id)}n.$parsers.push(function(e){var t={};return _.each(e,function(e){t[e.placeholder]=e.config}),t}),n.$validators["c8y-scada-mapping"]=function(e){var n=!1;return _.forEach(e,function(e,t){e=!_.isNull(e);r[t]=!e,n=n||!e}),!n},n.$overrideModelOptions({allowInvalid:!0}),n.$formatters.push(function(e){return _.map(e,function(e,t){return{placeholder:t,config:e}})}),n.$render=function(){o.mappings=n.$viewValue},_.assign(o,{hasError:r,clearMapping:function(e){e.config=null,a()},setMapping:function(t){s.set(i,c(o.deviceIds[t.placeholder])),l.openSelector({selectSingle:!0,managedObject:c(o.deviceIds[t.placeholder])}).then(function(e){t.config=e}).then(a).finally(function(){s.clear(i)})},editComputedProperty:function(t){s.set(i,c(o.deviceIds[t.placeholder])),p.edit(t.config).then(function(e){t.config.config=e}).then(a).finally(function(){s.clear(i)})},setFieldbusMapping:function(t){d.openFieldbusSelector({device:c(o.deviceIds[t.placeholder])}).then(function(e){t.config=e}).then(a)},propertyValueFor:function(e){var t=c(o.deviceIds[e.placeholder]);return f.getValueForMapping(t,e.config)},humanizeValue:function(e){return e=e.config&&_objectSpread(_objectSpread({},e.config),{},{label:y.getString(e.config.label)}),f.humanizeMapping(e)}}),o.$watch("devices",function(e){e&&_.forEach(o.mappings,u)},!0)},templateUrl:":::PLUGIN_PATH:::/views/mapping.html",scope:{device:"=",devices:"=",deviceIds:"=",onDeviceIdsChange:"&"}}}e.$inject=["SchemaPropertiesSvc","c8yComputedProperties","ScadaWidgetUtilSvc","c8yDeviceDatabase","contextDetailsSharedService","gettextCatalog"],angular.module("c8y.parts.scadaWidget").directive("c8yScadaMapping",e)})();