'use client'; import { parseBribeClaim, type BribeClaim } from '@/game/bribe-promises'; import { Input } from './ui/input'; type Recipient = { id: string; name: string }; export function bribeClaimInputError(value: unknown, recipients?: readonly Recipient[]): string | null { try { const claim = parseBribeClaim(value); return recipients && !recipients.some(recipient => recipient.id === claim.recipient) ? 'Choose one of the current bribe recipients.' : null; } catch (error) { return error instanceof Error ? error.message : 'Choose a recipient and a positive safe whole minimum.'; } } /** The parent supplies this turn and its current public recipient choices. */ export function BribeClaimFields(props: { value: BribeClaim; onChange: (claim: BribeClaim) => void; recipients: readonly Recipient[]; disabled?: boolean; }) { const error = bribeClaimInputError(props.value, props.recipients); const change = (value: unknown) => { if (!props.disabled && !bribeClaimInputError(value, props.recipients)) props.onChange(parseBribeClaim(value)); }; return
; }