"use client"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { cn } from "@/lib/utils"; export type UserStatus = "online" | "away" | "offline"; interface UserAvatarProps { photo?: string | null; name: string; size?: "sm" | "md" | "lg"; status?: UserStatus; /** @deprecated use status instead */ online?: boolean; } const sizeMap = { sm: "h-7 w-7 text-xs", md: "h-9 w-9 text-sm", lg: "h-11 w-11 text-base", }; const dotSizeMap = { sm: "h-2.5 w-2.5", md: "h-3 w-3", lg: "h-3.5 w-3.5", }; const statusColorMap: Record = { online: "bg-green-500", away: "bg-yellow-400", offline: "bg-gray-500", }; export function UserAvatar({ photo, name, size = "md", status, online }: UserAvatarProps) { // Resolve effective status (support legacy `online` prop) const effectiveStatus: UserStatus | undefined = status ?? (online === true ? "online" : online === false ? "offline" : undefined); return (
{photo && } {name.charAt(0).toUpperCase()} {effectiveStatus !== undefined && ( )}
); }