(()=>{function i(){this.isGood=function(e){return _.isObjectLike(e)&&e.id&&e.keyPath&&_.isArray(e.keyPath)&&0!==e.keyPath.length},this.humanize=function(e){return e.label},this.getValue=function(e,t){return r(e,t.keyPath)},this.getRawValue=this.getValue}function u(){this.isGood=function(e){return _.isString(e)&&0!==e.length},this.humanize=function(e){return['"',e,'"'].join("")},this.getValue=function(e,t){return t},this.getRawValue=this.getValue}function a(e,a){function n(t){return t?(Object.prototype.hasOwnProperty.call(t,"__fieldbusDeviceType")||(Object.defineProperty(t,"__fieldbusDeviceType",{configurable:!0,writable:!0,value:!1}),e.getDeviceTypeFromDevice(t).then(e.addDiscreteIOsMeta).then(e.addRegistersMeta).then(function(e){t.__fieldbusDeviceType=e})),t):""}function i(e,t,n){var i,u;return e.__fieldbusDeviceType&&("c8y_CoilStatus"===(u=_.head(t.keyPath))?i=_.find(e.__fieldbusDeviceType.c8y_Coils,{name:_.last(t.keyPath)}):"c8y_RegisterStatus"===u&&(i=_.find(e.__fieldbusDeviceType.c8y_Registers,{name:_.last(t.keyPath)})),i)?(n?a.getCurrentElementValueFormatted:a.getCurrentElementValue)(e,i):r(e,t.keyPath)}this.isGood=function(e){return _.isObjectLike(e)&&e.id&&e.keyPath&&_.isArray(e.keyPath)&&0!==e.keyPath.length&&!0===e.fieldbus},this.humanize=function(e){return e.label},this.getValue=function(e,t){return i(n(e),t,!0)},this.getRawValue=function(e,t){return i(n(e),t,!1)}}function r(e,t){for(var n=e,i=0;i<t.length&&null!=n;i++)n=n[t[i]];return n}angular.module("c8y.parts.scadaWidget").service("ScadaWidgetUtilSvc",["c8yDeviceDatabase","c8yModbusDevice",function(e,t){var n=[new a(e,t),new i,new u];this.humanizeMapping=function(e){return null==e?"":this.getHandler(e).humanize(e)},this.getValueForMapping=function(e,t){return null==t?"":this.getHandler(t).getValue(e,t)},this.getRawValueForMapping=function(e,t){return null==t?"":this.getHandler(t).getRawValue(e,t)},this.getHandler=function(t){var e=_.find(n,function(e){return e.isGood(t)});if(null==e)throw new Error("invalid mapping");return e}}])})();