'use client'; import { useId, useState } from 'react'; import type { Action, GameView } from '@/game/engine'; import { Button } from './ui/button'; import { CardInspector, CardRules } from './card-inspector'; /** Gift cards come only from this viewer's explicit server projection. */ export function RicheseGift({ game, act, busy, }: { game: GameView; act: (action: Action) => void; busy: boolean; }) { const id = useId(); const [selection, setSelection] = useState(''); const gift = game.richeseGift; if (!gift) return null; const owner = game.players.find((player) => player.id === gift.owner); const recipient = game.players.find( (player) => player.id === (gift.pending?.recipient ?? gift.recipient), ); const mine = gift.owner === game.me; const pending = gift.pending; if (pending) { if (![pending.owner, pending.recipient].includes(game.me)) return null; return (

Richese gift awaiting resolution

{mine ? 'You are giving' : `${owner?.name ?? 'Richese'} is giving you`}{' '} {pending.card?.name ?? 'a Richese card'} {mine ? ` to ${recipient?.name ?? 'your ally'}` : ''}. Resolve the current response before the card transfers. Inspecting it does not transfer the card.

{pending.card && (
)}
); } if (!mine) return null; const card = gift.cards.find((candidate) => candidate.id === selection) ?? gift.cards[0]; const reason = gift.blocked ?? (!recipient ? 'You need an ally to give a Richese card.' : !card ? 'No Richese card in your hand is available to give.' : null); return (
Give a Richese card to your ally

Give one Richese card from your hand to{' '} {recipient?.name ?? 'your ally'}. Your ally must have room. Karama can prevent this alliance power before the card transfers.

{gift.cards.length > 0 && ( <> {card && (
)} )} {reason && (

{reason}

)} {gift.unavailable.length > 0 && (

Cards unavailable to give

    {gift.unavailable.map( ({ card: unavailable, reason: unavailableReason }) => (
  • {unavailable.name}

    {unavailableReason}

  • ), )}
)}
); }