import { FormControl } from '@angular/forms'; import { ErrorValidator } from '../interface'; export class Utils { public static validateError(formControl: FormControl, errors: ErrorValidator[]): string[] { const errorDescriptions: string[] = []; if (errors) { for (const error of errors) { const errorKey = error.errorValidator; // Caso 1: Error estándar basado en la clave if (errorKey && formControl.hasError(errorKey)) { errorDescriptions.push(error.errorDescription); } // Caso 2: Manejo de condiciones adicionales else if (error.conditions) { for (const condition of error.conditions) { const hasErrorsValid = condition.hasError ? condition.hasError.every((key) => formControl.hasError(key)) : true; // Todas las claves en `hasError` deben existir const notErrorsValid = condition.notError ? condition.notError.every((key) => !formControl.hasError(key)) : true; // Todas las claves en `notError` NO deben existir if (hasErrorsValid && notErrorsValid) { errorDescriptions.push(error.errorDescription); } } } } } return errorDescriptions; } }