"use client"; import { useState } from "react"; import type { BoardState } from "@/lib/protocol"; interface BoardProps { board: BoardState; onColumnClick?: (column: number) => void; disabled?: boolean; lastMove?: { column: number; row: number } | null; player1?: string; player2?: string; currentTurnColor?: 1 | 2 | null; } export default function Board({ board, onColumnClick, disabled = false, lastMove, player1, player2, currentTurnColor, }: BoardProps) { const [hoveredCol, setHoveredCol] = useState(null); const canInteract = !disabled && !!onColumnClick; return (
{/* Player legend */} {player1 && player2 && (
{currentTurnColor === 1 ? (
) : (
)} {player1}
vs
{currentTurnColor === 2 ? (
) : (
)} {player2}
)} {/* Board */}
{Array.from({ length: 7 }, (_, col) => (
canInteract && onColumnClick?.(col)} onMouseEnter={() => canInteract && setHoveredCol(col)} onMouseLeave={() => setHoveredCol(null)} > {/* Drop arrow indicator */}
{/* Cells (top row first) */} {Array.from({ length: 6 }, (_, rowIdx) => { const row = 5 - rowIdx; const cell = board[col][row]; const isLast = lastMove?.column === col && lastMove?.row === row; return (
); })}
))}
{/* Column numbers */}
{Array.from({ length: 7 }, (_, col) => (
{col + 1}
))}
); }