'use client'; import { useId, useState } from 'react'; import type { Action, GameView } from '@/game/engine'; import { Button } from '@/components/ui/button'; type Mode = 'finish' | 'continue' | 'accept'; /** An event-bound action button; display data is never sent as authority. */ export function VictoryContinuationButton({ event, mode, extra, busy, act, children, }: { event: string; mode: Mode; extra?: number; busy: boolean; act: (action: Action) => void; children: string; }) { return ( ); } /** All viewers see the same offer. Only its current participant may respond. */ export function VictoryContinuation({ game, act, busy, }: { game: GameView; act: (action: Action) => void; busy: boolean; }) { const vote = game.victoryContinuation; const id = useId(); const [extraText, setExtraText] = useState('0'); if (!vote) return null; const name = (id: string) => game.players.find(player => player.id === id)?.name ?? id; const sides = vote.sides.map(side => side.map(name).join(' and ')).join('; '); const actor = name(vote.actor); const extra = Number(extraText); const validExtra = /^\d+$/.test(extraText) && Number.isSafeInteger(extra) && extra <= vote.maxExtra; const ownTurn = vote.actor === game.me; const proposal = vote.extra === null ? null : vote.extra === 0 ? 'Continue with the current stronghold targets.' : `Continue and increase the stronghold targets by ${vote.extra}.`; return (

Simultaneous victory

The qualifying sides are {sides}. They can finish the game, or unanimously agree to play another turn.

{proposal &&

Proposal: {proposal}

} {!ownTurn ? (

Waiting for {actor} to decide.

) : ( <> {vote.extra === null && ( )}
{vote.extra === null ? ( Propose another turn ) : ( Agree to continue )} Finish the game
)}
); }