"use client" import type { ChessPiece, Position } from "@/lib/chess-types" import ChessSquare from "./chess-square" interface ChessBoardProps { board: (ChessPiece | null)[][] selectedPiece: Position | null validMoves: Position[] onSquareClick: (position: Position) => void } export default function ChessBoard({ board, selectedPiece, validMoves, onSquareClick }: ChessBoardProps) { const isValidMove = (row: number, col: number) => { return validMoves.some((move) => move.row === row && move.col === col) } const isSelected = (row: number, col: number) => { return selectedPiece?.row === row && selectedPiece?.col === col } // Generate column labels (a-h) const columnLabels = Array.from({ length: 8 }, (_, i) => String.fromCharCode(97 + i)) // Generate row labels (1-8) const rowLabels = Array.from({ length: 8 }, (_, i) => 8 - i) return (
{/* Empty top-left corner */}
{/* Column labels (top) */} {columnLabels.map((label) => (
{label}
))} {/* Board with row labels */} {board.map((row, rowIndex) => ( <> {/* Row label */}
{rowLabels[rowIndex]}
{/* Chess squares */} {row.map((piece, colIndex) => ( onSquareClick({ row: rowIndex, col: colIndex })} /> ))} ))} {/* Empty bottom-left corner */}
{/* Column labels (bottom) */} {columnLabels.map((label) => (
{label}
))}
) }