import{A as g,B as v,j as h,k as d,m as F}from"./chunk-77K4SKWD.js";import{Y as p,aa as y,m as E,se as b,x as A}from"./chunk-IDYB4NXF.js";import{i as u}from"./chunk-AI7IVZV2.js";var k=(()=>{let c=class c{formBuilder=y(v);internalBuildForm(t,r={}){let o={},s={},i={};for(let n of Object.keys(t)){o[n]="";let a=t[n];if(this.isRecursiveField(a)){let l=this.internalBuildForm(a,r[n]);i[n]=l.form,o[n]=l.formErrors,s[n]=l.validationMessages;continue}a?.MESSAGES&&(s[n]=a.MESSAGES);let f=r[n]??"";a?.VALIDATORS?i[n]=[f,a.VALIDATORS]:i[n]=[f]}return{form:this.formBuilder.group(i),formErrors:o,validationMessages:s}}updateFormGroup(t,r,o,s,i={}){for(let e of b(s)){let n=s[e];if(this.isRecursiveField(n)){r[e]={},this.updateFormGroup(t[e],r[e],o[e],s[e],i[e]);continue}r[e]="",n?.MESSAGES&&(o[e]=n.MESSAGES);let a=i[e]??"";t.addControl(e+"",new F(a,n?.VALIDATORS,n?.ASYNC_VALIDATORS))}}addControlInFormArray(t){let{formArray:r,formErrors:o,validationMessages:s,controlName:i,formToBuild:e,defaultValues:n={}}=t,a=new d({});o[i]||(o[i]=[]),s[i]||(s[i]=[]);let f=o[i],l=s[i],S=r.controls.length;f.push({}),l.push({}),this.updateFormGroup(a,f[S],l[S],e,n),r.push(a)}removeControlFromFormArray(t){let{formArray:r,formErrors:o,validationMessages:s,index:i,controlName:e}=t,n=o[e],a=s[e];n.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:s,form:i}=this.formValidatorService.internalBuildForm(t,r);return i.events.pipe(A(e=>e instanceof h)).subscribe(()=>this.onStatusChanged({form:i,formErrors:o,validationMessages:s})),{form:i,formErrors:o,validationMessages:s}}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 s=r[o];if(s instanceof d){this.markAllAsDirty(s.controls);continue}s.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 s=t[o];s&&(typeof s=="string"?r.push(s):r=r.concat(this.grabAllErrors(s)))}return r}onStatusChanged(t){let{form:r,formErrors:o,validationMessages:s,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:s[e],onlyDirty:i});continue}o[e]="";let n=r.get(e);if(!n||i&&!n.dirty||!n.enabled||!n.errors)continue;let a=s[e];for(let f of Object.keys(n.errors)){let l=n.errors[f];if(a[f])o[e]+=a[f]+" ";else if(typeof l=="string")o[e]+=n.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:1cf7c077143c4c267fdafbe5508f191afcef21bad6aba22a3a8dc180e1003753*/
//# sourceMappingURL=chunk-IUO6RIHU.js.map
