export const PASSWORD_REQUIREMENTS = [
  { regex: /.{8,}/, text: "At least 8 characters", message: "Password must be at least 8 characters long" },
  { regex: /[a-z]/, text: "One lowercase letter", message: "Password must contain at least one lowercase letter" },
  { regex: /[A-Z]/, text: "One uppercase letter", message: "Password must contain at least one uppercase letter" },
  { regex: /\d/, text: "One number", message: "Password must contain at least one number" },
  { regex: /[-@$!%*?&#^]/, text: "One special character (-@$!%*?&#^)", message: "Password must contain at least one special character (-@$!%*?&#^)" },
];

export const COMMON_PASSWORDS = [
  "password",
  "123456",
  "123456789",
  "qwerty",
  "abc123",
  "password123",
];

/**
 * Validates password against all requirements
 * @returns error message if invalid, null if valid
 */
export function validatePassword(password: string): string | null {
  for (const req of PASSWORD_REQUIREMENTS) {
    if (!req.regex.test(password)) {
      return req.message;
    }
  }

  if (COMMON_PASSWORDS.includes(password.toLowerCase())) {
    return "This password is too common. Please choose a stronger password";
  }

  return null;
}
