import { AbstractControl, ValidationErrors } from "@angular/forms";

export class EmailValidator {
  static emailValidation(control: AbstractControl): ValidationErrors | null {
    const allowedDomains = ["gmail.com"];

    // if (control?.value) {
    //   const email = control.value as string;
    //   const domain = email.split("@")[1];
    //   if (!allowedDomains.includes(domain)) {
    //     return { emailValidation: true };
    //   }
    // }
    if (control?.value) {
      const email = control.value as string;
      const domain = email.split("@")[1];
      if (domain && (domain.endsWith(".com") || domain.endsWith(".co"))) {
        return null; // Email dengan domain .com atau .co diizinkan
      }
    }
    return { emailValidation: true };
    // return null;
  }
}
