export default function maskEmail(email: string): string {
  // Validate email (very basic)
  if (!email.includes("@")) return email;

  const [user, domain] = email.split("@");
  const [domainName, ...tldParts] = domain.split(".");

  // Mask user part
  const maskedUser =
    user.length > 2 ? `${user[0]}***${user[user.length - 1]}` : `${user[0]}***`;

  // Mask domain part (except TLD)
  const maskedDomain =
    domainName.length > 2
      ? `${domainName[0]}***${domainName[domainName.length - 1]}`
      : `${domainName[0]}***`;

  // Join TLD
  const tld = tldParts.length ? "." + tldParts.join(".") : "";

  return `${maskedUser}@${maskedDomain}${tld}`;
}
