import{A as F,i as A,j as d,l as v,z as g}from"./chunk-J3Q5GF64.js";import{Y as y,aa as p,m as S,qe as k,x as h}from"./chunk-WOSO3QBJ.js";import{i as u}from"./chunk-C2HMJUB7.js";var b=(()=>{let a=class a{formBuilder=p(F);internalBuildForm(t,r={}){let o={},s={},n={};for(let i of Object.keys(t)){o[i]="";let c=t[i];if(this.isRecursiveField(c)){let m=this.internalBuildForm(c,r[i]);n[i]=m.form,o[i]=m.formErrors,s[i]=m.validationMessages;continue}c?.MESSAGES&&(s[i]=c.MESSAGES);let f=r[i]??"";c?.VALIDATORS?n[i]=[f,c.VALIDATORS]:n[i]=[f]}return{form:this.formBuilder.group(n),formErrors:o,validationMessages:s}}updateFormGroup(t,r,o,s,n={}){for(let e of k(s)){let i=s[e];if(this.isRecursiveField(i)){r[e]={},this.updateFormGroup(t[e],r[e],o[e],s[e],n[e]);continue}r[e]="",i?.MESSAGES&&(o[e]=i.MESSAGES);let c=n[e]??"";t.addControl(e+"",new v(c,i?.VALIDATORS,i?.ASYNC_VALIDATORS))}}addControlInFormArray(t){let{formArray:r,formErrors:o,validationMessages:s,controlName:n,formToBuild:e,defaultValues:i={}}=t,c=new d({});o[n]||(o[n]=[]),s[n]||(s[n]=[]);let f=o[n],m=s[n],E=r.controls.length;f.push({}),m.push({}),this.updateFormGroup(c,f[E],m[E],e,i),r.push(c)}removeControlFromFormArray(t){let{formArray:r,formErrors:o,validationMessages:s,index:n,controlName:e}=t,i=o[e],c=s[e];i.splice(n,1),c.splice(n,1),r.removeAt(n)}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(a,"\u0275fac",function(r){return new(r||a)}),u(a,"\u0275prov",y({token:a,factory:a.\u0275fac}));let l=a;return l})();var x=(()=>{let a=class a{formValidatorService=p(b);buildForm(t,r={}){let{formErrors:o,validationMessages:s,form:n}=this.formValidatorService.internalBuildForm(t,r);return n.events.pipe(h(e=>e instanceof A)).subscribe(()=>this.onStatusChanged({form:n,formErrors:o,validationMessages:s})),{form:n,formErrors:o,validationMessages:s}}waitPendingCheck(t){if(t.status==="PENDING")return S(t.events.pipe(h(r=>r instanceof A&&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:n=!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:n});continue}o[e]="";let i=r.get(e);if(!i||n&&!i.dirty||!i.enabled||!i.errors)continue;let c=s[e];for(let f of Object.keys(i.errors)){let m=i.errors[f];if(c[f])o[e]+=c[f]+" ";else if(typeof m=="string")o[e]+=i.errors[f];else throw new Error("Form error value of "+e+" is invalid")}}}};u(a,"\u0275fac",function(r){return new(r||a)}),u(a,"\u0275prov",y({token:a,factory:a.\u0275fac}));let l=a;return l})();var M=class{formChanged=!1;form;formErrors;validationMessages;buildForm(a,C={}){let{formErrors:t,validationMessages:r,form:o}=this.formReactiveService.buildForm(a,C);this.form=o,this.formErrors=t,this.validationMessages=r}markAllAsDirty(){return this.formReactiveService.markAllAsDirty(this.form.controls)}forceCheck(){return this.formReactiveService.forceCheck(this.form,this.formErrors,this.validationMessages)}};export{b as a,x as b,M as c};
/**i18n:b44b17e72e4b9ae03afb92709eafda64a985c0c8f0453c865708cceafe42f927*/
//# sourceMappingURL=chunk-5RZNWWZS.js.map
