import { useState, useEffect } from 'react'; import { ChevronDown, Crown, Timer, RotateCcw, Settings } from 'lucide-react'; export default function ChessApp() { const [board, setBoard] = useState(initializeBoard()); const [selectedPiece, setSelectedPiece] = useState(null); const [currentPlayer, setCurrentPlayer] = useState('white'); const [gameMode, setGameMode] = useState('ai'); // 'ai', 'local', 'online' const [gameTime, setGameTime] = useState(600); // 10 minutes per player const [whiteTime, setWhiteTime] = useState(gameTime); const [blackTime, setBlackTime] = useState(gameTime); const [isTimerRunning, setIsTimerRunning] = useState(false); useEffect(() => { let interval; if (isTimerRunning) { interval = setInterval(() => { if (currentPlayer === 'white') { setWhiteTime(prev => Math.max(0, prev - 1)); } else { setBlackTime(prev => Math.max(0, prev - 1)); } }, 1000); } return () => clearInterval(interval); }, [isTimerRunning, currentPlayer]); function initializeBoard() { const board = Array(8).fill().map(() => Array(8).fill(null)); // Initialize pawns for (let i = 0; i < 8; i++) { board[1][i] = { type: 'pawn', color: 'black' }; board[6][i] = { type: 'pawn', color: 'white' }; } // Initialize other pieces const backRow = ['rook', 'knight', 'bishop', 'queen', 'king', 'bishop', 'knight', 'rook']; backRow.forEach((piece, i) => { board[0][i] = { type: piece, color: 'black' }; board[7][i] = { type: piece, color: 'white' }; }); return board; } function formatTime(seconds) { const minutes = Math.floor(seconds / 60); const remainingSeconds = seconds % 60; return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`; } function handleSquareClick(row, col) { if (!selectedPiece) { if (board[row][col] && board[row][col].color === currentPlayer) { setSelectedPiece({ row, col }); } } else { // Move validation would go here const newBoard = [...board]; newBoard[row][col] = board[selectedPiece.row][selectedPiece.col]; newBoard[selectedPiece.row][selectedPiece.col] = null; setBoard(newBoard); setSelectedPiece(null); setCurrentPlayer(current => current === 'white' ? 'black' : 'white'); if (!isTimerRunning) setIsTimerRunning(true); } } return (