import { Box, Grid, Typography } from "@mui/material"; import { PrimitiveAtom, atom, useAtomValue } from "jotai"; import { useEffect, useState } from "react"; import { getEvaluationBarValue } from "@/lib/chess"; import { Color } from "@/types/enums"; import { CurrentPosition } from "@/types/eval"; interface Props { height: number; boardOrientation?: Color; currentPositionAtom?: PrimitiveAtom; } export default function EvaluationBar({ height, boardOrientation, currentPositionAtom = atom({}), }: Props) { const [evalBar, setEvalBar] = useState({ whiteBarPercentage: 50, label: "0.0", }); const position = useAtomValue(currentPositionAtom); useEffect(() => { const bestLine = position?.eval?.lines[0]; if (!position.eval || !bestLine || bestLine.depth < 6) return; const evalBar = getEvaluationBarValue(position.eval); setEvalBar(evalBar); }, [position]); return ( {(evalBar.whiteBarPercentage < 50 && boardOrientation === Color.White) || (evalBar.whiteBarPercentage >= 50 && boardOrientation === Color.Black) ? evalBar.label : ""} {(evalBar.whiteBarPercentage >= 50 && boardOrientation === Color.White) || (evalBar.whiteBarPercentage < 50 && boardOrientation === Color.Black) ? evalBar.label : ""} ); }