'use client'; import { Button } from '@/components/ui/button'; import { FACTIONS } from '@/game/catalog'; import type { Action, GameView } from '@/game/engine'; /** Human recipients consent explicitly; AI recipients accept immediately. */ export function FactionSwap({ game, send, busy }: { game: GameView; send: (action: Action) => Promise; busy: boolean; }) { if (game.status !== 'lobby') return null; const factionName = (id: string) => FACTIONS.find((faction) => faction.id === id)?.name ?? id; const seatName = (id: string) => game.players.find((player) => player.id === id)?.name ?? 'Unknown player'; const swap = game.factionSwap; if (swap) return

Faction swap offer

{seatName(swap.from)} offers to exchange {factionName(swap.fromFaction)} with {seatName(swap.to)}'s {factionName(swap.toFaction)}.

Both players must agree. The factions change only if {seatName(swap.to)} accepts.

Lobby changes and starting the game are paused until the offer is accepted, declined, or canceled.

{game.me === swap.to &&
} {game.me === swap.from && }
; const self = game.players.find((player) => player.id === game.me); const targets = game.players.filter((player) => player.id !== game.me); return

Swap factions

Offer to exchange factions with another player. A human recipient must accept before either faction changes.

{game.factionDraft &&

Finish or cancel the faction draft before offering a swap.

} {game.players.some((player) => player.bot && player.id !== game.me) &&

AI seats accept immediately. The exchange clears human readiness.

} {self && !self.bot && targets.length > 0 ?
{targets.map((player) => )}
:

{self?.bot ? 'Only human players can offer a swap.' : 'A second seat is needed to offer a swap.'}

}
; }