import { useState } from "react"; import { useServerPlayers, useServerPlayerHistory } from "@/hooks/useServerDetail"; interface PlayerTableProps { serverId: number; } export function PlayerTable({ serverId }: PlayerTableProps) { const { data: playersData, isLoading } = useServerPlayers(serverId); const [showHistory, setShowHistory] = useState(false); if (isLoading) { return
Loading players...
; } const players = playersData?.players ?? []; const playerCount = playersData?.player_count ?? 0; return (

Online Players ({playerCount})

{showHistory ? ( ) : (
{players.length === 0 ? ( ) : ( players.map((player) => ( )) )}
Slot Name GUID IP Ping
No players online
{player.slot_id} {player.name} {player.guid} {player.ip} {player.ping}ms
)}
); } function PlayerHistorySection({ serverId }: { serverId: number }) { const [search, setSearch] = useState(""); const { data: historyData, isLoading } = useServerPlayerHistory(serverId, { limit: 50, search: search || undefined, }); if (isLoading) { return
Loading history...
; } const entries = historyData?.items ?? []; return (
setSearch(e.target.value)} className="neu-input w-full text-sm" />
{entries.length === 0 ? ( ) : ( entries.map((entry) => ( )) )}
Name GUID Joined Left Duration
No player history
{entry.name} {entry.guid} {formatTime(entry.joined_at)} {entry.left_at ? formatTime(entry.left_at) : "--"} {entry.session_duration_seconds ? formatDuration(entry.session_duration_seconds) : "--"}
); } function formatTime(iso: string): string { return new Date(iso).toLocaleString(); } function formatDuration(seconds: number): string { const h = Math.floor(seconds / 3600); const m = Math.floor((seconds % 3600) / 60); if (h > 0) return `${h}h ${m}m`; return `${m}m`; }