import type { PublicProfileResponse } from "@elysium/types"; import { useEffect, useState } from "react"; import { useGame } from "../../context/GameContext.js"; interface ProfilePageProps { discordId: string; } export const ProfilePage = ({ discordId }: ProfilePageProps): React.JSX.Element => { const { formatNumber } = useGame(); const [profile, setProfile] = useState(null); const [error, setError] = useState(null); const [copied, setCopied] = useState(false); useEffect(() => { fetch(`/api/profile/${discordId}`) .then(async (res) => { if (!res.ok) throw new Error("Player not found"); return res.json() as Promise; }) .then(setProfile) .catch((err: unknown) => { setError(err instanceof Error ? err.message : "Failed to load profile"); }); }, [discordId]); const handleCopy = (): void => { void navigator.clipboard.writeText(window.location.href).then(() => { setCopied(true); setTimeout(() => { setCopied(false); }, 2000); }); }; if (error) { return (

⚠️ {error}

← Play Elysium
); } if (!profile) { return (
Loading profile…
); } const s = profile.profileSettings; const avatarUrl = profile.avatar ? `https://cdn.discordapp.com/avatars/${discordId}/${profile.avatar}.png?size=128` : `https://cdn.discordapp.com/embed/avatars/${parseInt(discordId, 10) % 5}.png`; const memberSince = new Date(profile.createdAt).toLocaleDateString("en-GB", { year: "numeric", month: "long", day: "numeric", }); const visibleStats = [ s.showTotalGold && { icon: "πŸͺ™", value: formatNumber(profile.totalGoldEarned), label: "Total Gold Earned", date: false, }, s.showTotalClicks && { icon: "πŸ‘†", value: formatNumber(profile.totalClicks), label: "Total Clicks", date: false, }, s.showBossesDefeated && { icon: "πŸ’€", value: String(profile.bossesDefeated), label: "Bosses Defeated", date: false, }, s.showQuestsCompleted && { icon: "πŸ“œ", value: String(profile.questsCompleted), label: "Quests Completed", date: false, }, s.showAdventurersRecruited && { icon: "βš”οΈ", value: formatNumber(profile.adventurersRecruited), label: "Adventurers Recruited", date: false, }, s.showAchievementsUnlocked && { icon: "πŸ†", value: String(profile.achievementsUnlocked), label: "Achievements Unlocked", date: false, }, s.showGuildFounded && { icon: "πŸ“…", value: memberSince, label: "Guild Founded", date: true, }, ].filter(Boolean) as Array<{ icon: string; value: string; label: string; date: boolean }>; return (
{`${profile.username}'s

{profile.characterName}

@{profile.username}

{s.showPrestige && profile.prestigeCount > 0 && ( ⭐ Prestige {profile.prestigeCount} )}
{profile.bio && (

{profile.bio}

)} {visibleStats.length > 0 && (
{visibleStats.map((stat) => (
{stat.icon} {stat.value} {stat.label}
))}
)}
βš”οΈ Play Elysium
); };