import{Vo as lc,Wa as g,f as Ae,fr as S$1,po as ir}from"./chunk-B_pj7Jpm.js";import{D as k,E as j,R as z,c as Kn,y as be}from"./chunk-BPHMC4rz.js";var d=class l{formBuilder=g(Kn);internalBuildForm(e,r={}){let o={},a={},i={};for(let s of Object.keys(e)){o[s]=``;let n=e[s];if(this.isRecursiveField(n)){let c=this.internalBuildForm(n,r[s]);i[s]=c.form,o[s]=c.formErrors,a[s]=c.validationMessages;continue}n?.MESSAGES&&(a[s]=n.MESSAGES);let m=r[s]!==void 0?r[s]:``;n?.VALIDATORS?i[s]=[m,n.VALIDATORS]:i[s]=[m]}return{form:this.formBuilder.group(i),formErrors:o,validationMessages:a}}updateFormGroup(e,r,o,a,i={}){for(let t of lc(a)){let s=a[t];if(this.isRecursiveField(s)){r[t]={},this.updateFormGroup(e[t],r[t],o[t],a[t],i[t]);continue}r[t]=``,s?.MESSAGES&&(o[t]=s.MESSAGES);let n=i[t]??``;e.addControl(t+``,new z(n,s?.VALIDATORS,s?.ASYNC_VALIDATORS))}}addControlInFormArray(e){let{formArray:r,formErrors:o,validationMessages:a,controlName:i,formToBuild:t,defaultValues:s={}}=e,n=new j({});o[i]||(o[i]=[]),a[i]||(a[i]=[]);let m=o[i],c=a[i],p=r.controls.length;m.push({}),c.push({}),this.updateFormGroup(n,m[p],c[p],t,s),r.push(n)}removeControlFromFormArray(e){let{formArray:r,formErrors:o,validationMessages:a,index:i,controlName:t}=e,s=o[t],n=a[t];s.splice(i,1),n.splice(i,1),r.removeAt(i)}updateTreeValidity(e){for(let r of Object.keys(e.controls)){let o=e.controls[r];o instanceof j||o instanceof be?this.updateTreeValidity(o):o.updateValueAndValidity({emitEvent:!1})}}isRecursiveField(e){return e&&typeof e==`object`&&!e.MESSAGES&&!e.VALIDATORS}static ɵfac=function(r){return new(r||l)};static ɵprov=S$1({token:l,factory:l.ɵfac})};var S=class l{formValidatorService=g(d);buildForm(e,r={}){let{formErrors:o,validationMessages:a,form:i}=this.formValidatorService.internalBuildForm(e,r);return i.events.pipe(Ae(t=>t instanceof k)).subscribe(()=>this.onStatusChanged({form:i,formErrors:o,validationMessages:a})),{form:i,formErrors:o,validationMessages:a}}waitPendingCheck(e){if(e.status===`PENDING`)return ir(e.events.pipe(Ae(r=>r instanceof k&&r.status!==`PENDING`)))}markAllAsDirty(e){let r=e;for(let o of Object.keys(r)){let a=r[o];if(a instanceof j){this.markAllAsDirty(a.controls);continue}a.markAsDirty()}}forceCheck(e,r,o){this.onStatusChanged({form:e,formErrors:r,validationMessages:o,onlyDirty:!1})}grabAllErrors(e){let r=[];if(Array.isArray(e)){for(let o of e)r=r.concat(this.grabAllErrors(o));return r}for(let o of Object.keys(e)){let a=e[o];a&&(typeof a==`string`?r.push(a):r=r.concat(this.grabAllErrors(a)))}return r}onStatusChanged(e){let{form:r,formErrors:o,validationMessages:a,onlyDirty:i=!0}=e;for(let t of Object.keys(o)){if(o[t]&&typeof o[t]==`object`){this.onStatusChanged({form:r.controls[t],formErrors:o[t],validationMessages:a[t],onlyDirty:i});continue}o[t]=``;let s=r.get(t);if(!s||i&&!s.dirty||!s.enabled||!s.errors)continue;let n=a[t];for(let m of Object.keys(s.errors)){let c=s.errors[m];if(n[m])o[t]+=n[m]+` `;else if(typeof c==`string`)o[t]+=s.errors[m];else throw new Error(`Form error value of `+t+` is invalid`)}}}static ɵfac=function(r){return new(r||l)};static ɵprov=S$1({token:l,factory:l.ɵfac})};export{d as n,S as t};
//# debugId=726c8c0a-5e1c-5037-bd70-04c5db54dd1a
//# sourceMappingURL=chunk-BmH4cOwr.js.map