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