'use client'; import { useState } from 'react'; import type { Action, GameView } from '@/game/engine'; import { splitLocation } from '@/game/board'; import { Button } from './ui/button'; import { Input } from './ui/input'; export function IxSubstitution({ game: g, act, busy, }: { game: GameView; act: (action: Action) => void; busy: boolean; }) { const [sources, setSources] = useState>({}); const [recover, setRecover] = useState>({}); if (g.decision?.kind !== 'ixSubstitution') return null; const d = g.decision; const me = g.players.find((p) => p.id === g.me)!; const available = Object.entries(me.forces) .filter(([key]) => splitLocation(key).territory === d.territory) .map( ([key, count]) => [key, count - (me.elites?.forces[key] ?? 0)] as const, ) .filter(([, count]) => count > 0); const total = (value: Record) => Object.values(value).reduce((a, b) => a + b, 0); return ( <>

Exchange surviving suboids, one for one, to retain cyborgs lost in this battle. Retained cyborgs return to their casualty sectors. Opponents may cancel this substitution with Karama.

Suboids to sacrifice

{available.map(([key, max]) => ( ))}

Cyborgs to retain

{Object.entries(d.losses).map(([key, max]) => ( ))}

{total(sources)} suboids for {total(recover)} cyborgs

); }