'use client'; import { useId, useState } from 'react'; import type { Action, GameView } from '@/game/engine'; import { Button } from './ui/button'; export type AmbassadorNoFieldOffer = NonNullable< NonNullable['noField'] >; const titles: Record = { own: 'Use your No-Field', request: 'Request an allied No-Field', supply: 'Supply an allied No-Field', consent: 'Confirm allied No-Field shipment', }; const submitLabels: Record = { own: 'Confirm No-Field choice', request: 'Request selected No-Field shipment', supply: 'Offer selected No-Field shipment', consent: 'Accept selected No-Field offer', }; /** Receives complete server actions; selecting a marker never edits a physical shipment. */ export function AmbassadorNoFieldChoice({ offer, event, selectedKey, onSelect, act, busy, id = 'ambassador-no-field-choice', }: { offer: AmbassadorNoFieldOffer; event: string; selectedKey: string; onSelect: (key: string) => void; act: (action: Action) => void; busy: boolean; id?: string; }) { const selected = offer.options.find((option) => option.key === selectedKey); const reason = selected?.blocked ?? (selected ? null : 'Choose a No-Field option.'); return (

{titles[offer.stage]}

Choose a No-Field as the entire Ambassador shipment grant.

{offer.policy}

{reason &&

{reason}

} {offer.decline && ( )}
); } function AmbassadorNoFieldSelection({ offer, event, act, busy, }: { offer: AmbassadorNoFieldOffer; event: string; act: (action: Action) => void; busy: boolean; }) { const id = useId(); const [selectedKey, setSelectedKey] = useState(''); return ( ); } export function AmbassadorNoField({ game, act, busy, destination, sector, }: { game: GameView; act: (action: Action) => void; busy: boolean; destination?: string; sector?: number; }) { const entry = game.ambassadorEntry; if ( entry?.stage !== 'ship' || game.decision?.kind !== 'ecazAmbassador' || game.decision.player !== game.me || !entry.noField ) return null; const offer = entry.noField; const filtered = offer.stage === 'own' || offer.stage === 'request' ? { ...offer, options: offer.options.filter((option) => !option.territory || ((!destination || option.territory === destination) && (sector === undefined || option.sector === sector)), ), } : offer; return ( ); }