import{A as g,B as v,j as h,k as d,m as F}from"./chunk-VJWG2YMW.js";import{Be as b,Y as p,aa as y,m as E,x as A}from"./chunk-QIQJDAPQ.js";import{i as u}from"./chunk-3HGMGVFC.js";var k=(()=>{let c=class c{formBuilder=y(v);internalBuildForm(t,r={}){let o={},n={},i={};for(let s of Object.keys(t)){o[s]="";let a=t[s];if(this.isRecursiveField(a)){let l=this.internalBuildForm(a,r[s]);i[s]=l.form,o[s]=l.formErrors,n[s]=l.validationMessages;continue}a?.MESSAGES&&(n[s]=a.MESSAGES);let f=r[s]!==void 0?r[s]:"";a?.VALIDATORS?i[s]=[f,a.VALIDATORS]:i[s]=[f]}return{form:this.formBuilder.group(i),formErrors:o,validationMessages:n}}updateFormGroup(t,r,o,n,i={}){for(let e of b(n)){let s=n[e];if(this.isRecursiveField(s)){r[e]={},this.updateFormGroup(t[e],r[e],o[e],n[e],i[e]);continue}r[e]="",s?.MESSAGES&&(o[e]=s.MESSAGES);let a=i[e]??"";t.addControl(e+"",new F(a,s?.VALIDATORS,s?.ASYNC_VALIDATORS))}}addControlInFormArray(t){let{formArray:r,formErrors:o,validationMessages:n,controlName:i,formToBuild:e,defaultValues:s={}}=t,a=new d({});o[i]||(o[i]=[]),n[i]||(n[i]=[]);let f=o[i],l=n[i],S=r.controls.length;f.push({}),l.push({}),this.updateFormGroup(a,f[S],l[S],e,s),r.push(a)}removeControlFromFormArray(t){let{formArray:r,formErrors:o,validationMessages:n,index:i,controlName:e}=t,s=o[e],a=n[e];s.splice(i,1),a.splice(i,1),r.removeAt(i)}updateTreeValidity(t){for(let r of Object.keys(t.controls)){let o=t.controls[r];o instanceof d||o instanceof g?this.updateTreeValidity(o):o.updateValueAndValidity({emitEvent:!1})}}isRecursiveField(t){return t&&typeof t=="object"&&!t.MESSAGES&&!t.VALIDATORS}};u(c,"\u0275fac",function(r){return new(r||c)}),u(c,"\u0275prov",p({token:c,factory:c.\u0275fac}));let m=c;return m})();var x=(()=>{let c=class c{formValidatorService=y(k);buildForm(t,r={}){let{formErrors:o,validationMessages:n,form:i}=this.formValidatorService.internalBuildForm(t,r);return i.events.pipe(A(e=>e instanceof h)).subscribe(()=>this.onStatusChanged({form:i,formErrors:o,validationMessages:n})),{form:i,formErrors:o,validationMessages:n}}waitPendingCheck(t){if(t.status==="PENDING")return E(t.events.pipe(A(r=>r instanceof h&&r.status!=="PENDING")))}markAllAsDirty(t){let r=t;for(let o of Object.keys(r)){let n=r[o];if(n instanceof d){this.markAllAsDirty(n.controls);continue}n.markAsDirty()}}forceCheck(t,r,o){this.onStatusChanged({form:t,formErrors:r,validationMessages:o,onlyDirty:!1})}grabAllErrors(t){let r=[];if(Array.isArray(t)){for(let o of t)r=r.concat(this.grabAllErrors(o));return r}for(let o of Object.keys(t)){let n=t[o];n&&(typeof n=="string"?r.push(n):r=r.concat(this.grabAllErrors(n)))}return r}onStatusChanged(t){let{form:r,formErrors:o,validationMessages:n,onlyDirty:i=!0}=t;for(let e of Object.keys(o)){if(o[e]&&typeof o[e]=="object"){this.onStatusChanged({form:r.controls[e],formErrors:o[e],validationMessages:n[e],onlyDirty:i});continue}o[e]="";let s=r.get(e);if(!s||i&&!s.dirty||!s.enabled||!s.errors)continue;let a=n[e];for(let f of Object.keys(s.errors)){let l=s.errors[f];if(a[f])o[e]+=a[f]+" ";else if(typeof l=="string")o[e]+=s.errors[f];else throw new Error("Form error value of "+e+" is invalid")}}}};u(c,"\u0275fac",function(r){return new(r||c)}),u(c,"\u0275prov",p({token:c,factory:c.\u0275fac}));let m=c;return m})();export{k as a,x as b};
/**i18n:d946b30bd8b2b104e368c275b91cb34bb911fa22291c946a5e8c8a6facd9306d*/
//# sourceMappingURL=chunk-N6HA4CTN.js.map
