import Image from "next/image"; import { Award, Clock3, DatabaseZap, RadioTower } from "lucide-react"; import type { DiscordMemberProfile, DiscordRole } from "@/lib/discord/discord"; import type { LevelProgress } from "@/lib/leaderboard/level-progress"; import { formatInteger, formatVoiceDuration } from "@/lib/leaderboard/ranking"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Badge } from "@/components/ui/badge"; import { DiscordAvatar, DiscordServerTag } from "@/components/avatar"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { Progress } from "@/components/ui/progress"; import { Separator } from "@/components/ui/separator"; import { discordColorToHex, } from "@/lib/discord/profile-appearance"; type RankedXp = LevelProgress & { rank: number | null }; type RankedVoice = { totalSeconds: string; rank: number | null }; type ProfilePassportProps = { userName: string; userImage: string; profile: DiscordMemberProfile | null; profileUnavailable: boolean; xp: RankedXp | null; voice: RankedVoice | null; }; const DEFAULT_ROLE_COLOR = "#99aab5"; function toHex(value: number) { return discordColorToHex(value); } function initials(value: string) { return value.trim().slice(0, 2).toLocaleUpperCase("th-TH") || "?"; } function rankLabel(rank: number | null) { return rank ? `#${formatInteger(String(rank))}` : "ยังไม่ติดอันดับ"; } function RoleBadge({ role }: { role: DiscordRole }) { const color = role.color === 0 ? DEFAULT_ROLE_COLOR : toHex(role.color); return ( {role.name} ); } function UnavailableAlert({ kind }: { kind: "xp" | "voice" }) { const Icon = kind === "xp" ? DatabaseZap : RadioTower; return ( {kind === "xp" ? "โหลดข้อมูล XP ไม่สำเร็จ" : "โหลดเวลาในห้องเสียงไม่สำเร็จ"} ลองเปิดหน้านี้ใหม่อีกครั้งเมื่อระบบพร้อมใช้งาน ); } function XpCard({ xp }: { xp: RankedXp | null }) { return ( ความก้าวหน้า XP {xp && อันดับ {rankLabel(xp.rank)}} เลเวลและ XP สะสมจากกิจกรรมใน Discord {xp ? (

เลเวลปัจจุบัน

{xp.level}

XP สะสม

{formatInteger(xp.totalXp)} XP

{xp.isMaxLevel ? (
เลเวลสูงสุด

คุณถึงเลเวลสูงสุดของระบบแล้ว

) : (
{formatInteger(xp.xpIntoLevel)} / {formatInteger(xp.xpRequired)} XP อีก {formatInteger(xp.xpToNextLevel)} XP
)}
) : ( )}
อันดับคำนวณจาก XP สะสมของสมาชิกเลเวล 1 ขึ้นไป
); } function VoiceCard({ voice }: { voice: RankedVoice | null }) { const duration = voice?.totalSeconds === "0" ? "0 นาที" : voice ? formatVoiceDuration(voice.totalSeconds) : null; return ( เวลาในห้องเสียง {voice && อันดับ {rankLabel(voice.rank)}} เวลารวมจากห้องเสียงและห้องเวทีที่ยังอยู่ในเซิร์ฟเวอร์ {voice ? (

{duration}

) : ( )}
ห้องที่ถูกลบหรือไม่อยู่ในเซิร์ฟเวอร์แล้วจะไม่รวมในยอดนี้
); } export function ProfilePassport({ userName, userImage, profile, profileUnavailable, xp, voice, }: ProfilePassportProps) { const displayName = profile?.globalName || userName || profile?.username || "สมาชิก Erika!"; const username = profile?.username || userName; const avatarUrl = profile?.avatarUrl || userImage; return (
{profile?.bannerUrl && ( )}
{displayName} {profile && }
@{username}
{xp && เลเวล {xp.level}}
{profileUnavailable && ( ข้อมูล Discord บางส่วนยังไม่พร้อม กำลังแสดงชื่อและรูปจากบัญชีที่เข้าสู่ระบบ บทบาทและแบนเนอร์อาจยังไม่ครบ )} {profile && profile.roles.length > 0 && (

บทบาทในเซิร์ฟเวอร์

{profile.roles.map((role) => )}
)}
โปรไฟล์นี้เห็นได้เฉพาะเมื่อคุณเข้าสู่ระบบด้วยบัญชี Discord ของตัวเอง
); }