import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Eye, Check, X } from 'lucide-react'; import { toast } from 'sonner'; import { apiClient } from 'app'; interface Props { tableId: string; currentUserId: string; isEliminated: boolean; spectateRequests: string[]; isHost: boolean; players: Array<{ user_id: string; display_name?: string | null }>; } export default function SpectateControls({ tableId, currentUserId, isEliminated, spectateRequests, isHost, players }: Props) { const [requesting, setRequesting] = useState(false); const [granting, setGranting] = useState(null); const handleRequestSpectate = async () => { setRequesting(true); try { await apiClient.request_spectate({ table_id: tableId }); toast.success('Spectate request sent to host'); } catch (error) { toast.error('Failed to request spectate access'); } finally { setRequesting(false); } }; const handleGrantSpectate = async (userId: string, granted: boolean) => { setGranting(userId); try { await apiClient.grant_spectate({ table_id: tableId, user_id: userId, granted }); toast.success(granted ? 'Spectate access granted' : 'Spectate access denied'); } catch (error) { toast.error('Failed to process spectate request'); } finally { setGranting(null); } }; const getUserName = (userId: string) => { const player = players.find(p => p.user_id === userId); return player?.display_name || userId.slice(0, 8); }; return (
{/* Eliminated Player - Request to Spectate */} {isEliminated && (

You've been eliminated

Request permission from the host to spectate the remaining players

)} {/* Host - Pending Spectate Requests */} {isHost && spectateRequests.length > 0 && (

Spectate Requests

{spectateRequests.length}
{spectateRequests.map((userId) => (
{getUserName(userId)}
))}
)}
); }