(()=>{function e(e,n,l){var a=e.Validation.RuleType,r=e.Validation.ResourceDataType,o=e.Validation.ValueType,e=e.Validation.RuleName,t=[{type:a.GT,name:e.GT},{type:a.LT,name:e.LT},{type:a.GTE,name:e.GTE},{type:a.LTE,name:e.LTE},{type:a.EQ,name:e.EQ},{type:a.NEQ,name:e.NEQ}],u=this;function i(){u.rule.type=(e=>(e=_.find(t,{name:e}))?e.type:void 0)(u.selectedRule),u.rule.arg.valueType=u.selectedType,u.rule.arg.value=u.value,u.showDateTime=s()&&T(),u.formValidation=p(),u.onChange({rule:u.rule})}function m(){var e;u.showDateTime=T()&&s(),u.showDateTime&&(e=(e=>{var a,t;return _.isString(e)?(a=moment(e)).isValid()||(t=_.toNumber(e),_.isNumber(t)&&(a=moment(new Date(t)))):_.isNumber(e)&&(a=moment(new Date(e))),{asString:_.get(a,"_d"),asMs:a?a.valueOf():void 0}})(u.dateTimeValue||_.get(u.rule,"arg.value")),u.value=e.asMs,u.dateTimeValue=e.asString,u.rule.arg.value=e.asMs)}function s(){return!(!_.isUndefined(u.selectedType)||u.resourceDataType!==r.TIME)||u.selectedType===o.DATE}function T(){return u.resourceDataType===r.TIME}function d(){u.dateTimeValue=moment(new Date(_.toNumber(u.value)))}function p(){var e=_.get(u.rule,"arg.valueType"),a="",t="";return e===o.STRING&&u.resourceDataType===r.BOOLEAN&&(t='"true"'.concat(" ",l.getString("or"),' "false"'),a="(true|false)"),e===o.OBJECTLINK&&(t=n("Refer to a resource using the following format: /Object/Instance/Resource, for example, /3303/0/5700."),a="/[\\d*/]*\\d+"),e===o.NUMBER&&u.resourceDataType===r.INTEGER&&(t=n("Only values of type Integer allowed."),a="-?\\d+"),e===o.NUMBER&&u.resourceDataType===r.FLOAT&&(t=n("Only values of type Float allowed."),a="-?\\d*[.]\\d+"),e===o.DATE&&u.resourceDataType===r.TIME&&(t=n("Only numbers allowed, for example, 1528197925677."),a="\\d+"),{pattern:a,tooltip:t}}function c(e){e=_.find(t,{type:e});return e?e.name:void 0}u.$onInit=function(){var e;_.assign(u,{change:i,dateTimeChange:m,reflectInDateTimePicker:d,selectedRule:c(_.get(u.rule,"type",_.first(u.options))),selectedType:_.get(u.rule,"arg.valueType"),ruleOptions:(e=u.options,_.map(e,c)),formValidation:p(),value:_.get(u.rule,"arg.value"),dateTimeValue:m(),$onChange:u.onChange({rule:u.rule})})}}e.$inject=["c8yLwm2m","gettext","gettextCatalog"],angular.module("c8y.lwm2m").component("c8yLwm2mValidationRule",{templateUrl:":::PLUGIN_PATH:::/lwm2mValidationRules/lwm2mValidationRule.html",controller:e,controllerAs:"vm",bindings:{rule:"<",options:"<",isLast:"<",valueTypes:"<",onAdd:"&",onRemove:"&",onChange:"&",resourceDataType:"@"}})})();