import { Initials } from "@suphark/ui/components/shared/initials"; import { cn } from "@suphark/ui/lib/utils"; import type { ReactNode } from "react"; import type { Presence } from "./presence-dot"; export interface UserIdentityProps { name: string | null | undefined; /** บรรทัดรอง — ปกติคืออีเมล */ email?: ReactNode; /** รูปโปรไฟล์ (ไม่มี = ตัวย่อชื่อพร้อมสีพื้นคงที่ต่อชื่อ) */ src?: string | null; /** ต่อท้ายชื่อ เช่น `` หรือป้าย "คุณ" */ badge?: ReactNode; /** ใต้บรรทัดอีเมล เช่น "เข้าใช้ล่าสุด 2 ชม.ที่แล้ว" */ hint?: ReactNode; /** sm = ใช้ในแถวตาราง (avatar size-7), default = size-9 */ size?: "sm" | "default"; /** จุดสถานะบน avatar: online / away / busy / offline */ status?: Presence; /** ซ่อน avatar (เมื่อแถวมีรูปอยู่แล้ว) */ hideAvatar?: boolean; className?: string; } /** * ชื่อผู้ใช้ + อีเมล + avatar ในบล็อกเดียว — แถวตาราง, เมนู, การ์ดสมาชิก (Pi Auth เขียนซ้ำ ~15 จุด) * ชื่อว่าง = แสดงอีเมลเป็นบรรทัดหลักแทน (ผู้ใช้ที่ยังไม่ตั้งชื่อ) */ export function UserIdentity({ name, email, src, badge, hint, size = "default", status, hideAvatar = false, className, }: UserIdentityProps) { const displayName = name?.trim() || null; const primary = displayName ?? (typeof email === "string" ? email : null); const secondary = displayName ? email : null; return (
{!hideAvatar && ( )}
{primary ?? "—"} {badge} {secondary && {secondary}} {hint && {hint}}
); }