import{i as y,k as S,y as v,z as g}from"./chunk-7VHQBARM.js";import{$ as A,Y as p,ge as k,md as E}from"./chunk-QXV2GR6R.js";import{i as m,j as h}from"./chunk-JJ4RDTEF.js";var b=(()=>{let f=class f{constructor(r){m(this,"formBuilder");this.formBuilder=r}buildForm(r,s={}){var i;let o={},n={},e={};for(let t of Object.keys(r)){o[t]="";let c=r[t];if(this.isRecursiveField(c)){let d=this.buildForm(c,s[t]);e[t]=d.form,o[t]=d.formErrors,n[t]=d.validationMessages;continue}c!=null&&c.MESSAGES&&(n[t]=c.MESSAGES);let u=(i=s[t])!=null?i:"";c!=null&&c.VALIDATORS?e[t]=[u,c.VALIDATORS]:e[t]=[u]}return{form:this.formBuilder.group(e),formErrors:o,validationMessages:n}}updateFormGroup(r,s,o,n,e={}){var a;for(let i of k(n)){s[i]="";let t=n[i];if(this.isRecursiveField(t)){this.updateFormGroup(r[i],s[i],o[i],n[i],e[i]);continue}t!=null&&t.MESSAGES&&(o[i]=t.MESSAGES);let c=(a=e[i])!=null?a:"";r.addControl(i+"",new S(c,t==null?void 0:t.VALIDATORS,t==null?void 0:t.ASYNC_VALIDATORS))}}addControlInFormArray(r){let{formArray:s,formErrors:o,validationMessages:n,controlName:e,formToBuild:a,defaultValues:i={}}=r,t=new y({});o[e]||(o[e]=[]),n[e]||(n[e]=[]);let c=o[e],u=n[e],d=s.controls.length;c.push({}),u.push({}),this.updateFormGroup(t,c[d],u[d],a,i),s.push(t)}removeControlFromFormArray(r){let{formArray:s,formErrors:o,validationMessages:n,index:e,controlName:a}=r,i=o[a],t=n[a];i.splice(e,1),t.splice(e,1),s.removeAt(e)}updateTreeValidity(r){for(let s of Object.keys(r.controls)){let o=r.controls[s];o instanceof y||o instanceof v?this.updateTreeValidity(o):o.updateValueAndValidity({emitEvent:!1})}}isRecursiveField(r){return r&&typeof r=="object"&&!r.MESSAGES&&!r.VALIDATORS}};m(f,"\u0275fac",function(s){return new(s||f)(A(g))}),m(f,"\u0275prov",p({token:f,factory:f.\u0275fac}));let l=f;return l})();var R=(()=>{let f=class f{constructor(r){m(this,"formValidatorService");this.formValidatorService=r}buildForm(r,s={}){let{formErrors:o,validationMessages:n,form:e}=this.formValidatorService.buildForm(r,s);return e.statusChanges.subscribe(()=>h(this,null,function*(){yield this.waitPendingCheck(e),this.onStatusChanged({form:e,formErrors:o,validationMessages:n})})),{form:e,formErrors:o,validationMessages:n}}waitPendingCheck(r){return h(this,null,function*(){if(r.status==="PENDING")do yield E(10);while(r.status==="PENDING")})}markAllAsDirty(r){let s=r;for(let o of Object.keys(s)){let n=s[o];if(n instanceof y){this.markAllAsDirty(n.controls);continue}n.markAsDirty()}}forceCheck(r,s,o){this.onStatusChanged({form:r,formErrors:s,validationMessages:o,onlyDirty:!1})}onStatusChanged(r){let{form:s,formErrors:o,validationMessages:n,onlyDirty:e=!0}=r;for(let a of Object.keys(o)){if(o[a]&&typeof o[a]=="object"){this.onStatusChanged({form:s.controls[a],formErrors:o[a],validationMessages:n[a],onlyDirty:e});continue}o[a]="";let i=s.get(a);if(!i||e&&!i.dirty||!i.enabled||!i.errors)continue;let t=n[a];for(let c of Object.keys(i.errors)){let u=i.errors[c];if(t[c])o[a]+=t[c]+" ";else if(typeof u=="string")o[a]+=i.errors[c];else throw new Error("Form error value of "+a+" is invalid")}}}};m(f,"\u0275fac",function(s){return new(s||f)(A(b))}),m(f,"\u0275prov",p({token:f,factory:f.\u0275fac}));let l=f;return l})();var F=class{constructor(){m(this,"formChanged",!1);m(this,"form");m(this,"formErrors");m(this,"validationMessages")}buildForm(f,C={}){let{formErrors:r,validationMessages:s,form:o}=this.formReactiveService.buildForm(f,C);this.form=o,this.formErrors=r,this.validationMessages=s}waitPendingCheck(){return h(this,null,function*(){return this.formReactiveService.waitPendingCheck(this.form)})}markAllAsDirty(){return this.formReactiveService.markAllAsDirty(this.form.controls)}forceCheck(){return this.formReactiveService.forceCheck(this.form,this.formErrors,this.validationMessages)}};export{b as a,R as b,F as c};
/**i18n:224bcada6943fe8b17ea60808c2d370cec9507c3bd670ebe71692d099a3befa1*/
//# sourceMappingURL=chunk-BNV6WX3E.js.map
