"use client"; import { useCallback, useEffect, useState } from "react"; import { Eye, Plus, RefreshCw, Bomb } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { ROUND_TARGET_OPTIONS } from "@/lib/minigames/bomperator/constants"; import type { BomperatorMatchSummary, BomperatorView } from "@/lib/minigames/bomperator/types"; import { createBomperatorMatch, fetchBomperatorMatch, joinBomperatorMatch, listBomperatorMatches, } from "@/app/(frontend)/minigames/bomperator/actions"; const PHASE_LABELS: Record = { waiting: "Waiting for technicians", lobby: "In the waiting room", countdown: "Starting", battle: "In progress", roundEnd: "Round over", complete: "Finished", }; export function BomperatorLobby({ onOpenMatch, currentUserId, }: { onOpenMatch: (match: BomperatorView) => void; currentUserId: number | string; }) { const [matches, setMatches] = useState(null); const [roundTarget, setRoundTarget] = useState(3); const [error, setError] = useState(null); const [busyId, setBusyId] = useState(null); const refresh = useCallback(() => { void listBomperatorMatches() .then((result) => { if (result.success && result.data) setMatches(result.data); else setError(result.error ?? "Could not load matches."); }) .catch(() => setError("Could not load matches.")); }, []); useEffect(() => { refresh(); const id = window.setInterval(refresh, 4000); return () => window.clearInterval(id); }, [refresh]); const create = useCallback(async () => { setBusyId("new"); setError(null); const created = await createBomperatorMatch(roundTarget); if (!created.success || !created.data) { setBusyId(null); setError(created.error ?? "Could not create a match."); return; } const snapshot = await fetchBomperatorMatch(created.data.matchId); setBusyId(null); if (snapshot.success && snapshot.data) onOpenMatch(snapshot.data); else refresh(); }, [onOpenMatch, refresh, roundTarget]); const enter = useCallback( async (matchId: string, spectate: boolean) => { setBusyId(matchId); setError(null); const result = spectate ? await fetchBomperatorMatch(matchId) : await joinBomperatorMatch(matchId); setBusyId(null); if (result.success && result.data) onOpenMatch(result.data); else { setError(result.error ?? "Could not enter the match."); refresh(); } }, [onOpenMatch, refresh], ); return (
Ordnance Disposal drills

Open a depot and share the link, or join one below. Last technician standing wins the round.

Best of {ROUND_TARGET_OPTIONS.map((option) => ( ))}
{error && (

{error}

)} {matches === null ? (

Loading matches…

) : matches.length === 0 ? (

No live drills. Start one and send the link to your squad.

) : (
    {matches.map((match) => { const open = match.phase === "waiting" || match.phase === "lobby"; const canJoin = !match.joined && open && match.seatedCount < match.maxSeats; return (
  • {match.name ?? "Ordnance Disposal"} {match.hostName} · {match.seatedCount}/{match.maxSeats} · first to{" "} {match.roundTarget} · {PHASE_LABELS[match.phase]}
    {!open && !match.joined && ( )}
  • ); })}
)}
); }