"use client"; import { clearBuzzes, markBuzz } from "@/app/admin/live-actions"; import { Button } from "@/components/ui/button"; import { formatBuzzGap, type BuzzerView } from "@/lib/buzzer"; import type { LiveGame } from "@/lib/live-view"; import { ErrorText } from "./error-text"; import { useAction } from "./use-action"; /** * Who buzzed for the current question, in order. The host marks the answering team: * "Got it" gives the point and ends the question, "Wrong" passes the turn down the order. */ export function BuzzerPanel({ eventId, game, buzzer }: { eventId: string; game: LiveGame; buzzer: BuzzerView }) { const { pending, error, run } = useAction(); const { buzzes, answeringTeamId } = buzzer; const decided = buzzes.some((entry) => entry.result === "correct"); // Only a direct game takes the point; in a judged game the judges' scores stand. const pointCriterion = game.scoringMode === "direct" ? game.criteria[0] : undefined; return (

Buzzers

{buzzes.length === 0 ? (

{buzzer.open ? "Waiting for a buzz…" : "Closed — the game is done."}

) : (
    {buzzes.map((entry, index) => { const answering = entry.teamId === answeringTeamId; return (
  1. {index + 1} {entry.name} {index === 0 ? "first" : formatBuzzGap(entry.afterFirstMs)} {answering && ( <> )} {entry.result && ( <> {entry.result === "correct" ? "✓ Got it" : "✗ Wrong"} )}
  2. ); })}
)}

{decided ? "Answered. Press “Next question” to open the buzzers again." : buzzes.length > 0 && !answeringTeamId ? "Nobody is waiting to answer. The buzzers are still open." : pointCriterion ? `“Got it” adds 1 to ${pointCriterion.label}. “Wrong” passes to the next team.` : "Judged game: “Got it” adds no point — the judges score. “Wrong” passes to the next team."}

{error}
); }