import { Grid2 as Grid } from "@mui/material"; import MovesLine from "./movesLine"; import { useMemo } from "react"; import { useAtomValue } from "jotai"; import { boardAtom, gameAtom, gameEvalAtom } from "../../../states"; import { MoveClassification } from "@/types/enums"; export default function MovesPanel() { const game = useAtomValue(gameAtom); const board = useAtomValue(boardAtom); const gameEval = useAtomValue(gameEvalAtom); const gameMoves = useMemo(() => { const gameHistory = game.history(); const boardHistory = board.history(); const history = gameHistory.length ? gameHistory : boardHistory; if (!history.length) return undefined; const moves: { san: string; moveClassification?: MoveClassification }[][] = []; for (let i = 0; i < history.length; i += 2) { const items = [ { san: history[i], moveClassification: gameHistory.length ? gameEval?.positions[i + 1]?.moveClassification : undefined, }, ]; if (history[i + 1]) { items.push({ san: history[i + 1], moveClassification: gameHistory.length ? gameEval?.positions[i + 2]?.moveClassification : undefined, }); } moves.push(items); } return moves; }, [game, board, gameEval]); if (!gameMoves?.length) return null; return ( {gameMoves?.map((moves, idx) => ( san).join()}-${idx}`} moves={moves} moveNb={idx + 1} /> ))} ); }