"use client"; import { useState } from "react"; import Link from "next/link"; import { ArrowLeft } from "lucide-react"; import { motion } from "motion/react"; import type { BoardTheme } from "~/utils/theme-utils"; import { Board } from "~/components/chess/board"; import { Controls } from "~/components/chess/controls"; import { EngineControls } from "~/components/chess/engine-controls"; import { GameEndModal } from "~/components/chess/game-end-modal"; import { MoveHistory } from "~/components/chess/move-history"; import { Timers } from "~/components/chess/timers"; import { Button } from "~/components/ui/button"; import { useChessGame } from "~/hooks/use-chess-game"; import { useSound } from "~/hooks/use-sound"; /** * Main chess game page - demonstrates full integration */ const ChessPage: React.FC = () => { const [theme, setTheme] = useState("wood"); const [engineEnabled, setEngineEnabled] = useState(false); const [engineThinking, setEngineThinking] = useState(false); const [showGameEndModal, setShowGameEndModal] = useState(false); // Timer state const [whiteTime, setWhiteTime] = useState(600); // 10 minutes const [blackTime, setBlackTime] = useState(600); const [timerRunning, setTimerRunning] = useState(false); // Initialize sound const sound = useSound({ enabled: true, volume: 0.5 }); // Initialize chess game const game = useChessGame({ onMove: (move) => { // Play sound based on move type if (move.captured) { sound.play("capture"); } else { sound.play("move"); } // Start timer if not running if (!timerRunning) { setTimerRunning(true); } }, onGameOver: () => { sound.play("gameEnd"); setShowGameEndModal(true); setTimerRunning(false); }, }); const handleRematch = () => { game.resetGame(); setShowGameEndModal(false); setWhiteTime(600); setBlackTime(600); setTimerRunning(false); }; const handleTimeUpdate = (color: "w" | "b", time: number) => { if (color === "w") { setWhiteTime(time); } else { setBlackTime(time); } }; const handleTimeExpired = () => { sound.play("gameEnd"); setTimerRunning(false); setShowGameEndModal(true); }; const handleEngineMove = () => { setEngineThinking(true); // Simulate engine thinking setTimeout(() => { setEngineThinking(false); sound.play("notify"); }, 2000); }; return (
{/* Header */}

Chess Board

{/* Spacer for centering */} {/* Game status */}

{game.status}

{/* Main game layout */}
{/* Left column - Move history and engine */}
setEngineEnabled(!engineEnabled)} onRequestMove={handleEngineMove} />
{/* Center - Chess board */}
sound.setEnabled(!sound.enabled)} theme={theme} onThemeChange={setTheme} />
{/* Right column - Timers */}
setTimerRunning(!timerRunning)} />
{/* Info section */}

Features

🎮 Interactive Board

Drag & drop or click to move pieces

🎨 Multiple Themes

Choose from 4 beautiful board themes

⏱️ Chess Clocks

Time controls with pause/resume

📝 Move History

Full game notation tracking

💾 Import/Export

Load and save games as FEN/PGN

🔊 Sound Effects

Audio feedback for all moves

{/* Game end modal */} setShowGameEndModal(false)} />
); }; export default ChessPage;