import React, { useState, useEffect } from 'react'; import { Button } from '../components/ui/Button'; import { ArrowLeft, Trophy, Coins, Brain, Sparkles, Loader2, RefreshCw, User, Crown, BarChart3, Zap, TrendingUp, Hexagon } from 'lucide-react'; import { StorageService } from '../services/storageService'; import { UserProfile } from '../types'; interface ArcadeLeaderboardProps { onExit: () => void; } export const ArcadeLeaderboard: React.FC = ({ onExit }) => { const [leaders, setLeaders] = useState([]); const [loading, setLoading] = useState(true); const [currentUser, setCurrentUser] = useState(null); const [activeTab, setActiveTab] = useState<'points' | 'speed' | 'memory' | 'danphe' | 'flexibility' | 'truth' | 'mandala'>('points'); const fetchData = async () => { setLoading(true); try { const [allUsers, profile] = await Promise.all([ StorageService.getLeaderboard(50, activeTab as any), StorageService.getProfile() ]); setLeaders(allUsers || []); // Ensure array setCurrentUser(profile); } catch (e) { console.error("Failed to fetch leaderboard", e); setLeaders([]); } finally { setLoading(false); } }; useEffect(() => { fetchData(); }, [activeTab]); const getRankStyle = (index: number) => { switch(index) { case 0: return "bg-yellow-500/20 border-yellow-500 text-yellow-400 shadow-[0_0_20px_rgba(234,179,8,0.4)] ring-1 ring-yellow-500/50"; // Gold case 1: return "bg-slate-400/20 border-slate-400 text-slate-300 shadow-[0_0_15px_rgba(148,163,184,0.3)]"; // Silver case 2: return "bg-orange-500/20 border-orange-500 text-orange-400 shadow-[0_0_15px_rgba(249,115,22,0.3)]"; // Bronze default: return "bg-gray-800/50 border-gray-700 text-gray-400"; } }; const getScoreDisplay = (user: UserProfile) => { if (activeTab === 'points') return user.points || 0; return (user.highScores as any)?.[activeTab] || 0; }; return (
{/* Background Ambience */}
{/* Header */}
{/* Back Button on Left with margin */} {/* Title Centered but slightly right */}

RANKINGS

Global Hall of Fame

{/* Content */}
{/* Tabs */}
{[ { id: 'points', label: 'Global Karma', icon: Coins, color: 'text-yellow-400' }, { id: 'speed', label: 'Speed Zone', icon: Zap, color: 'text-red-400' }, { id: 'memory', label: 'Memory Shore', icon: Brain, color: 'text-cyan-400' }, { id: 'danphe', label: 'Danphe Rush', icon: TrendingUp, color: 'text-emerald-400' }, { id: 'flexibility', label: 'Mental Agility', icon: RefreshCw, color: 'text-pink-400' }, { id: 'truth', label: 'Logic Fuses', icon: Sparkles, color: 'text-amber-400' }, { id: 'mandala', label: 'Mandala Mind', icon: Hexagon, color: 'text-purple-400' }, ].map(tab => ( ))}
{loading ? (

Syncing Records...

) : (
Rank
Player
Role
Score
{leaders.length === 0 && (

No records found yet.

Be the first to claim the throne!

)} {leaders.map((user, index) => { const isMe = currentUser?.id === user.id; return (
{/* Rank */}
{index < 3 ? : '#'} {index + 1}
{/* Player */}
{user.name} {isMe &&
}

{user.name}

{isMe &&

You

}
{/* Role */}
{user.role}
{/* Score */}
{getScoreDisplay(user).toLocaleString()}
); })}
)}
); };