import { useState, useEffect } from 'react'; import { apiClient } from 'app'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Trophy, Users, Crown, XCircle } from 'lucide-react'; import { toast } from 'sonner'; interface HistoryEntry { round_number: number; winner_user_id: string | null; winner_name: string | null; disqualified_users: string[]; completed_at: string; } interface Props { tableId: string; } export default function HistoryTable({ tableId }: Props) { const [history, setHistory] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const fetchHistory = async () => { try { const response = await apiClient.get_round_history({ table_id: tableId }); const data = await response.json(); setHistory(data.rounds || []); } catch (error) { console.error('Failed to fetch round history:', error); toast.error('Failed to load game history'); } finally { setLoading(false); } }; fetchHistory(); }, [tableId]); const formatTimestamp = (timestamp: string) => { const date = new Date(timestamp); return date.toLocaleString('en-US', { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }); }; if (loading) { return (
); } if (history.length === 0) { return (

No rounds completed yet

); } return (
{history.map((round) => (
Round {round.round_number}
{formatTimestamp(round.completed_at)}
{/* Winner */} {round.winner_user_id && (
Winner: {round.winner_name || round.winner_user_id.slice(0, 8)}
)} {/* Disqualified Players */} {round.disqualified_users.length > 0 && (

Disqualified:

{round.disqualified_users.map((userId) => ( {userId.slice(0, 8)} ))}
)}
))}
); }