"use client"; import { useState } from "react"; import { usePathname } from "next/navigation"; import Image from "next/image"; import { LogOut } from "lucide-react"; import { signOut } from "next-auth/react"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Button } from "@/components/ui/button"; import type { DiscordRole } from "@/lib/discord"; export interface DiscordMemberProfile { id: string; username: string; globalName: string | null; avatarUrl: string | null; bannerUrl: string | null; accentColor: number | null; roles: DiscordRole[]; } const toHex = (n: number) => `#${n.toString(16).padStart(6, "0")}`; const DEFAULT_ROLE_COLOR = "#99aab5"; function RolePill({ role }: { role: DiscordRole }) { const colorHex = role.color === 0 ? DEFAULT_ROLE_COLOR : toHex(role.color); return (
{role.name}
); } export function DropdownMenuAvatar({ userName, userImage, profile, showName = true, }: { userName: string; userImage: string; profile: DiscordMemberProfile | null; showName?: boolean; }) { const [imgError, setImgError] = useState(false); const pathname = usePathname(); const displayAvatar = profile?.avatarUrl || userImage; const displayName = profile?.globalName || userName; const username = profile?.username || userName; const bannerStyle = { height: 100, backgroundColor: profile?.accentColor ? toHex(profile.accentColor) : "hsl(var(--muted))", backgroundImage: profile?.bannerUrl ? `url(${profile.bannerUrl})` : "none", backgroundSize: "cover" as const, backgroundPosition: "center" as const, }; return ( {/* Banner Section */}
{/* Body Area */}
{/* Avatar - Absolute Positioned to overlap banner and body */}
{!imgError && displayAvatar && ( {displayName} setImgError(true)} unoptimized /> )}
{/* Profile Info Section */}
{displayName}
{username}
{/* Roles Section */} {profile && profile.roles.length > 0 && (
Roles / บทบาท
{profile.roles.map((role) => ( ))}
)}
{/* Footer / Sign Out */}
signOut({ callbackUrl: pathname })} className="text-destructive" > ออกจากระบบ
); }