'use client'; import { useId, useState } from 'react'; import type { Action, GameView } from '@/game/engine'; import { battleCardLabel } from '@/game/battle-cards'; import { Button } from './ui/button'; import { CardInspector, CardRules } from './card-inspector'; export function MoritaniRetention({ game, act, busy, }: { game: GameView; act: (action: Action) => void; busy: boolean; }) { const groupId = useId(); const [selected, setSelected] = useState(null); const decision = game.decision; if (decision?.kind !== 'moritaniRetention' || decision.player !== game.me) return null; const nexus = decision.source === 'nexus'; const canKeep = !nexus || !!game.nexusMoritaniRetention?.canKeep; const choose = (keep: string | null): Action => nexus ? { type: 'decision', event: decision.event, keep } : { type: 'decision', keep }; const me = game.players.find((player) => player.id === game.me); if (!me) return null; const cards = (me.hand ?? []).filter((card) => decision.cards.includes(card.id), ); const selectedCard = cards.find((card) => card.id === selected); const owner = game.players.find((player) => player.id === decision.owner); const location = game.combatLocations.find(place => place.id === decision.territory)?.name ?? decision.territory; const disabled = busy || !!game.response || !!game.truthtrance; return (
{nexus ? ( <>

You lost the battle in {location}. Every loser with an eligible played card gets this choice. If you hold the Moritani Nexus card while unallied, spend it to retain one played card a winner could keep; otherwise continue.

Used cards with mandatory discard cannot be retained. Spending the Nexus card is public; your other hand cards remain private.

) : ( <>

You lost the battle in {location}. Your Moritani ally{owner ? `, ${owner.name},` : ''} lets you choose one eligible card played in that battle to keep. Using this ability is optional.

Declare one card, then the table may respond with Karama before you retain it. If the power is canceled, all these cards are discarded. Declining also discards them.

)}
Choose one card to retain {cards.map((card) => (

{battleCardLabel(card.kind)}

))}
{!cards.length && (

No eligible card remains in your hand. Decline to continue.

)}
); }