import { createHash } from "crypto";

// Gravatar keys avatars by MD5 of the trimmed, lowercased email — no other
// normalization is defined by their API.
export function gravatarUrl(email: string, size = 200): string {
  const hash = createHash("md5").update(email.trim().toLowerCase()).digest("hex");
  // d=404 makes Gravatar 404 instead of serving a placeholder when no avatar
  // is registered for the hash, so callers relying on <img onError> fallback
  // (e.g. the Avatar component's initials fallback) behave correctly.
  return `https://www.gravatar.com/avatar/${hash}?s=${size}&d=404`;
}
