import { motion } from 'framer-motion';
export default function ChessBoard({ board, onSquareClick, selectedPos, validMoves, lastMove, turn }) {
const files = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
const ranks = ['8', '7', '6', '5', '4', '3', '2', '1'];
return (
{/* Board Border Decoration */}
{board.map((row, rowIndex) => (
row.map((piece, colIndex) => {
const isBlackSquare = (rowIndex + colIndex) % 2 === 1;
const isSelected = selectedPos?.r === rowIndex && selectedPos?.c === colIndex;
const isValidMove = validMoves.some(m => m.r === rowIndex && m.c === colIndex);
const isLastMoveFrom = lastMove?.from.r === rowIndex && lastMove?.from.c === colIndex;
const isLastMoveTo = lastMove?.to.r === rowIndex && lastMove?.to.c === colIndex;
const isCheck = false; // Simplified for this demo
return (
onSquareClick(rowIndex, colIndex)}
className={`
chess-square
${isBlackSquare ? 'bg-[#769656]' : 'bg-[#eeeed2]'}
${isSelected ? '!bg-comic-yellow ring-4 ring-inset ring-black z-20' : ''}
${(isLastMoveFrom || isLastMoveTo) && !isSelected ? 'bg-comic-blue/40' : ''}
`}
>
{/* Coordinate Labels */}
{colIndex === 0 && (
{ranks[rowIndex]}
)}
{rowIndex === 7 && (
{files[colIndex]}
)}
{/* Valid Move Indicator */}
{isValidMove && !piece && (
)}
{isValidMove && piece && (
)}
{/* Piece */}
{piece && (
{getPieceSymbol(piece)}
)}
);
})
))}
);
}
const isWhitePiece = (p) => p === p.toUpperCase();
const isBlackPiece = (p) => p === p.toLowerCase();
const getPieceSymbol = (p) => {
const map = {
'K': '♔', 'Q': '♕', 'R': '♖', 'B': '♗', 'N': '♘', 'P': '♙',
'k': '♚', 'q': '♛', 'r': '♜', 'b': '♝', 'n': '♞', 'p': '♟',
};
return map[p] || '';
};