{"version":3,"sources":["src/app/shared/services/form-errors.service.ts"],"sourcesContent":["import { Injectable, signal } from '@angular/core';\nimport { FormControl, FormGroup } from '@angular/forms';\nimport { BehaviorSubject } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class FormErrorsService {\n public errors = signal('');\n public httpErrors$: BehaviorSubject<\n { field_name: string; msg: string }[] | undefined\n > = new BehaviorSubject(undefined);\n\n public setHttpErrors(errors): void {\n this.httpErrors$.next(errors);\n }\n\n public handleHttpErrors(form: FormGroup) {\n const errors: { [key: string]: string | undefined } = {};\n this.httpErrors$.value?.forEach((error) => {\n if (\n form.controls['passwordGroup'] &&\n form.controls['passwordGroup']['controls'][error.field_name]\n ) {\n const control: FormControl =\n form.controls['passwordGroup']['controls'][\n error.field_name\n ];\n control.setErrors({ incorrect: true });\n control.valueChanges.subscribe(() => {\n errors[error.field_name] = undefined;\n });\n } else if (form.controls[error.field_name]) {\n form.controls[error.field_name]?.setErrors({ incorrect: true });\n form.controls[error.field_name].valueChanges.subscribe(() => {\n errors[error.field_name] = undefined;\n });\n }\n errors[error.field_name] = error.msg;\n });\n return errors;\n }\n}\n"],"names":["FormErrorsService","errors","signal","httpErrors$","BehaviorSubject","undefined","setHttpErrors","next","handleHttpErrors","form","value","forEach","error","controls","field_name","control","setErrors","incorrect","valueChanges","subscribe","msg","factory","ɵfac","providedIn"],"mappings":";;uDAKA,IAAaA,GAAiB,IAAA,CAAxB,MAAOA,CAAiB,CACnBC,OAASC,EAAe,EAAE,EAC1BC,YAEH,IAAIC,EAAgBC,MAAS,EAE1BC,cAAcL,EAAM,CACvB,KAAKE,YAAYI,KAAKN,CAAM,CAChC,CAEOO,iBAAiBC,EAAe,CACnC,IAAMR,EAAgD,CAAA,EACtD,YAAKE,YAAYO,OAAOC,QAASC,GAAS,CACtC,GACIH,EAAKI,SAAS,eACdJ,EAAKI,SAAS,cAAiB,SAAYD,EAAME,UAAU,EAC7D,CACE,IAAMC,EACFN,EAAKI,SAAS,cAAiB,SAC3BD,EAAME,UAAU,EAExBC,EAAQC,UAAU,CAAEC,UAAW,EAAI,CAAE,EACrCF,EAAQG,aAAaC,UAAU,IAAK,CAChClB,EAAOW,EAAME,UAAU,EAAIT,MAC/B,CAAC,CACL,MAAWI,EAAKI,SAASD,EAAME,UAAU,IACrCL,EAAKI,SAASD,EAAME,UAAU,GAAGE,UAAU,CAAEC,UAAW,EAAI,CAAE,EAC9DR,EAAKI,SAASD,EAAME,UAAU,EAAEI,aAAaC,UAAU,IAAK,CACxDlB,EAAOW,EAAME,UAAU,EAAIT,MAC/B,CAAC,GAELJ,EAAOW,EAAME,UAAU,EAAIF,EAAMQ,GACrC,CAAC,EACMnB,CACX,4CAlCSD,EAAiB,6BAAjBA,EAAiBqB,QAAjBrB,EAAiBsB,UAAAC,WADJ,MAAM,CAAA,SACnBvB,CAAiB,GAAA","debug_id":"3f764611-edfe-5690-a179-9d0a6a75ab34"}