'use client'; import type { Action, GameView } from '@/game/engine'; import { parseShipmentExpression, ShipmentClaimError, shipmentExpressionOf, shipmentClaimHasNoField, type ShipmentExpression, } from '@/game/shipment-promises'; import { shipmentExpressionInputError } from '@/game/shipment-expression-input'; import { truthQuestionText, type TruthQuestion } from '@/game/truthtrance'; import { ShipmentExpressionFields } from './shipment-expression-fields'; import { Button } from './ui/button'; /** Public authoring only. Feasibility and answer choices stay authoritative. */ export function TruthShipmentQuestion({ game, question, busy, act, onChange }: { game: GameView; question: Extract; busy: boolean; act: (action: Action) => void; onChange: (expression: ShipmentExpression) => void; }) { const ownsQuestion = () => !!game.me && game.players.some(player => player.id === game.me) && game.truthtrance?.stage === 'ask' && game.truthtrance.queue[0]?.player === game.me; const hasTarget = () => question.target !== game.me && game.players.some(player => player.id === question.target); const supported = () => hasTarget() && game.truthShipmentTargets.includes(question.target) && (!shipmentClaimHasNoField(question) || game.players.some(player => player.id === question.target && player.faction === 'richese')); const inputError = () => { try { parseShipmentExpression(shipmentExpressionOf(question), { allowConstants: false }); return null; } catch (error) { if (error instanceof ShipmentClaimError) return error.message; throw error; } }; const blocked = () => busy || !ownsQuestion() || !supported() || !!inputError(); const error = inputError(); return <> {hasTarget() ? player.id === question.target && player.faction === 'richese')} disabled={busy || !ownsQuestion() || !game.truthShipmentTargets.includes(question.target)} onChange={next => { if (!busy && ownsQuestion() && hasTarget() && game.truthShipmentTargets.includes(question.target) && !shipmentExpressionInputError(next)) onChange(next); }} /> :

Choose another seated player for this question.

} {!supported() &&

Choose an eligible respondent with an unused shipment this turn and finish pending decisions.

}
{error ?? truthQuestionText(question, id => game.allLeaders.find(leader => leader.id === id)?.name ?? id, id => game.combatLocations.find(location => location.id === id)?.name ?? id)}
{error &&

{error}

} ; }