"use client"; import React, { useState } from "react"; import { ArrowLeftRight, Download, RotateCcw, Settings, Undo, Upload, Volume2, VolumeOff, } from "lucide-react"; import { motion } from "motion/react"; import { toast } from "sonner"; import type { UseChessGameReturn } from "~/hooks/use-chess-game"; import type { BoardTheme } from "~/utils/theme-utils"; import { Button } from "~/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "~/components/ui/dialog"; import { Label } from "~/components/ui/label"; import { Textarea } from "~/components/ui/textarea"; import { cn } from "~/lib/utils"; import { downloadPGN } from "~/utils/pgn-utils"; interface ControlsProps { game: UseChessGameReturn; soundEnabled: boolean; onToggleSound: () => void; theme: BoardTheme; onThemeChange: (theme: BoardTheme) => void; className?: string; } const THEMES: BoardTheme[] = ["default", "wood", "marble", "neon"]; /** * Game controls component (reset, undo, flip, settings) */ const Controls: React.FC = ({ game, soundEnabled, onToggleSound, theme, onThemeChange, className, }) => { const [importDialogOpen, setImportDialogOpen] = useState(false); const [exportDialogOpen, setExportDialogOpen] = useState(false); const [settingsOpen, setSettingsOpen] = useState(false); const [fenInput, setFenInput] = useState(""); const [pgnInput, setPgnInput] = useState(""); const handleUndo = () => { const success = game.undoMove(); if (success) { toast.success("Move undone"); } else { toast.error("No moves to undo"); } }; const handleReset = () => { game.resetGame(); toast.success("Game reset"); }; const handleFlip = () => { game.flipBoard(); }; const handleExportPGN = () => { const pgn = game.exportPGN(); downloadPGN(pgn, `chess-game-${Date.now()}.pgn`); toast.success("Game exported as PGN"); }; const handleImportFEN = () => { const success = game.loadFEN(fenInput); if (success) { toast.success("Position loaded from FEN"); setImportDialogOpen(false); setFenInput(""); } else { toast.error("Invalid FEN string"); } }; const handleImportPGN = () => { const success = game.loadPGN(pgnInput); if (success) { toast.success("Game loaded from PGN"); setImportDialogOpen(false); setPgnInput(""); } else { toast.error("Invalid PGN string"); } }; const handleCopyFEN = () => { const fen = game.exportFEN(); navigator.clipboard.writeText(fen); toast.success("FEN copied to clipboard"); }; const handleCopyPGN = () => { const pgn = game.exportPGN(); navigator.clipboard.writeText(pgn); toast.success("PGN copied to clipboard"); }; return ( {/* Undo */} {/* Reset */} {/* Flip board */} {/* Sound toggle */} {/* Import */} Import Game Load a game from FEN or PGN notation