export const generateSecurePassword = (): string => {
  const length = 16;
  const charset =
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+";
  let password = "";

  // Ensure at least one of each required character type
  password += charset.match(/[A-Z]/)![0]; // Capital letter
  password += charset.match(/[a-z]/)![0]; // Lowercase letter
  password += charset.match(/[0-9]/)![0]; // Number
  password += charset.match(/[!@#$%^&*()_+]/)![0]; // Special character

  // Fill rest with random characters
  for (let i = password.length; i < length; i++) {
    const randomIndex = Math.floor(Math.random() * charset.length);
    password += charset[randomIndex];
  }

  // Shuffle the password
  return password
    .split("")
    .sort(() => Math.random() - 0.5)
    .join("");
};
