import{g as u}from"./chunk-MDIMQ3H3.js";import{a as r}from"./chunk-3DEA4WWC.js";import{Xb as p,kb as a,ra as g}from"./chunk-GJDGQISV.js";import{a as s,b as o}from"./chunk-SNAKHGZS.js";var l=class h{control=g(u);_minLength=8;set minLength(t){r.IsEmpty(this._inputType)&&(this._minLength=t,this.initRegex())}_maxLength=10;set maxLength(t){r.IsEmpty(this._inputType)&&(this._maxLength=t,this.initRegex())}_inputType;set inputType(t){this._inputType=t,this._inputType==="phone"?(this._minLength=8,this._maxLength=13):this._inputType==="nationalId"&&(this._minLength=8,this._maxLength=16),this.initRegex()}regex;initRegex(){this.regex=new RegExp(`^[0-9]{${this._minLength},${this._maxLength}}$`)}onInput(t){let e=t.target.value;e=this.formatInput(e),this.control.control?.setValue(e,{emitEvent:!1}),this.validateMinLength(e)}onBlur(t){let n=t.target;this.validateMinLength(n.value)}validateMinLength(t){if(t.length<this._minLength&&t.length!==0)this.control.control?.setErrors(o(s({},this.control.control?.errors),{minLength:{message:this.getMessageMinLength(),requiredLength:this._minLength,actualLength:t.length}}));else{let n=s({},this.control.control?.errors);n?.minLength&&(delete n.minLength,this.control.control?.setErrors(Object.keys(n).length===0?null:n))}}getMessageMinLength(){let t="";switch(this._inputType){case"phone":t=`Phone Number must be at least ${this._minLength} digits long.`;break;case"nationalId":t=`National ID must be at least ${this._minLength} digits long.`;break;default:t=`Field must be at least ${this._minLength} digits long.`}return t}formatInput(t){return this.regex.test(t)?t:t.replace(/\D/g,"").substring(0,this._maxLength)}static \u0275fac=function(n){return new(n||h)};static \u0275dir=a({type:h,selectors:[["","numericInputOnly",""]],hostBindings:function(n,e){n&1&&p("input",function(i){return e.onInput(i)})("blur",function(i){return e.onBlur(i)})},inputs:{minLength:"minLength",maxLength:"maxLength",inputType:[0,"numericInputOnly","inputType"]}})};export{l as a};
