"use client"; import { Eye, Shield } from "lucide-react"; import { cn } from "@/lib/utils"; import type { PublicPlayerView } from "@/lib/minigames/blackjack"; import { handValue } from "@/lib/minigames/blackjack"; import type { BlackjackSnapshot } from "@/app/(frontend)/minigames/blackjack/actions"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { BlackjackClock } from "./BlackjackClock"; type SeatedSnapshot = BlackjackSnapshot & { readonly you: NonNullable; }; const PHASE_COPY: Record = { betting: "Place your bet", insurance: "Insurance offered", player: "Play your hand", dealer: "Dealer plays", "round-complete": "Round settled", }; interface BlackjackActionConsoleProps { readonly snapshot: SeatedSnapshot; readonly hostSeatId: number | null; readonly spectator?: boolean; readonly onJoin?: () => void; readonly isSuperuser?: boolean; readonly starting: boolean; readonly leaving: boolean; readonly onStart: () => void; readonly onLeave: () => void; } export function BlackjackActionConsole({ snapshot, hostSeatId, spectator = false, onJoin, isSuperuser = false, starting, leaving, onStart, onLeave, }: BlackjackActionConsoleProps) { const view = snapshot.you; const viewerPlayer: PublicPlayerView | undefined = view.players.find( (player) => player.seatId === view.viewerSeat, ); const seatsOpen = snapshot.seats.filter((seat) => seat === null).length; const chipsInPlay = viewerPlayer?.hands.reduce((sum, hand) => sum + hand.bet, 0) ?? 0; const viewerInitial = (viewerPlayer?.name ?? "You").trim().charAt(0).toUpperCase() || "?"; const yourHandTotals = view.yourHands.map((hand) => handValue(hand.cards).total); const isHost = view.viewerSeat === hostSeatId; return (
{spectator ? ( <>

Spectating

{seatsOpen > 0 ? `${seatsOpen} seat${seatsOpen > 1 ? "s" : ""} open` : "No open seats"}

) : ( <>

{viewerPlayer?.name ?? "You"} {isSuperuser && ( )} (you)

Bankroll {viewerPlayer?.bankroll.toLocaleString() ?? "0"}

{isHost && Host} {viewerPlayer && viewerPlayer.bankrupt && ( Busted )}
{yourHandTotals.length > 0 && ( You have:{" "} {yourHandTotals .map((total, index) => yourHandTotals.length > 1 ? `H${index + 1} ${total}` : String(total), ) .join(" / ")} )}
)}
{!spectator && (
)} {spectator && seatsOpen > 0 && onJoin && ( )} {view.phase !== "round-complete" && (
)}
{view.phase === "round-complete" && (
Round settled The next betting round starts automatically.
{snapshot.nextRoundAt && ( )} {!spectator && ( )}
)} {starting && Starting}
); }