import { useEffect, useState, type ReactNode } from "react"; import type { EmailAddress } from "@/jmap/types"; import { avatarColor, initials } from "@/lib/address"; import { useContacts } from "@/store/contacts"; import { contactPhoto } from "@/lib/contacts"; import { t } from "@/lib/i18n"; export function Avatar({ who, size, className }: { who: EmailAddress | { name?: string | null; email?: string } | string | null | undefined; size?: "sm" | "lg" | "xl"; className?: string }) { const email = typeof who === "string" ? who : (who?.email ?? ""); const name = typeof who === "string" ? who : (who?.name ?? who?.email ?? ""); // Whatever cards are held count, the reader's own or a shared book's; the // photo is fetched from the account the card belongs to. const photo = useContacts((s) => { if (!email) return null; const c = s.lookupByEmail(email); const account = c ? (s.accountOfCard(c.id) ?? s.accountId) : null; return c && account ? contactPhoto(c, account) : null; }); return ( ); } export function Switch({ checked, onChange, label, hint, disabled, locked }: { checked: boolean; onChange: (v: boolean) => void; label?: ReactNode; hint?: ReactNode; disabled?: boolean; locked?: boolean }) { const sw = (