'use client'; import type { Action } from '@/game/engine'; import { Button } from './ui/button'; /** The ordering frame is public: eligibility depends on who queued a question, * never on whether any player holds Juice of Sapho. */ export type SaphoTruthOrderFrame = { event: string; holders: string[]; passed: string[]; revision: number; }; export type SaphoTruthOrderChoice = { card: string; mode: 'first' | 'last' }; export type SaphoTruthOrderProps = { frame: SaphoTruthOrderFrame; me: string; choices: SaphoTruthOrderChoice[]; act: (action: Action) => void; busy: boolean; }; /** The authoritative action is revalidated by the server. These local checks * also avoid sending a callback after its visible event or revision changed. */ function currentFrame(props: SaphoTruthOrderProps, frame: SaphoTruthOrderFrame, event: string, revision: number): boolean { return !props.busy && props.frame === frame && frame.event === event && frame.revision === revision && typeof event === 'string' && event.length > 0 && Number.isSafeInteger(revision) && revision >= 0 && frame.holders.includes(props.me) && !frame.passed.includes(props.me); } export function SaphoTruthOrderPass(props: SaphoTruthOrderProps) { const { frame } = props, event = frame.event, revision = frame.revision; const canAct = () => currentFrame(props, frame, event, revision); return ; } export function SaphoTruthOrderChoiceButton(props: SaphoTruthOrderProps & { choice: SaphoTruthOrderChoice }) { const { frame, choice } = props, event = frame.event, revision = frame.revision; const card = choice.card, mode = choice.mode; const canAct = () => currentFrame(props, frame, event, revision) && typeof card === 'string' && card.length > 0 && (mode === 'first' || mode === 'last') && choice.card === card && choice.mode === mode && props.choices.some(item => item.card === card && item.mode === mode); return ; } /** Render the same public pass opportunity to every queued holder. The choices * array contains only this viewer's server-quoted, privately held cards. */ export function SaphoTruthOrder(props: SaphoTruthOrderProps) { const { frame, me } = props; const eligible = frame.holders.includes(me), passed = frame.passed.includes(me); return

Truthtrance question order

Before the questions begin, each player who queued a Truthtrance may continue or use an available order change. Questions from the same player stay together.

{frame.passed.length} of {frame.holders.length} players have finished this choice.

{eligible && !passed ? <> {props.choices.map(choice => )} :

{eligible ? 'You have finished this choice.' : 'Waiting for the players who queued questions.'}

}
; }