|
| 1 | +import React from 'react' |
| 2 | +import { Highlight, MoveMap, BlunderMeter } from '../Analysis' |
| 3 | +import { useAnalysisController } from 'src/hooks' |
| 4 | +import { AnalyzedGame } from 'src/types' |
| 5 | +import { GameTree } from 'src/types/base/tree' |
| 6 | +import { Chess } from 'chess.ts' |
| 7 | + |
| 8 | +// Create a mock analyzed game for when no real game is available |
| 9 | +const createMockAnalyzedGame = (): AnalyzedGame => ({ |
| 10 | + id: 'mock', |
| 11 | + blackPlayer: { name: 'Player', rating: undefined }, |
| 12 | + whitePlayer: { name: 'Player', rating: undefined }, |
| 13 | + moves: [], |
| 14 | + availableMoves: [], |
| 15 | + gameType: 'play', |
| 16 | + termination: { |
| 17 | + result: '*', |
| 18 | + winner: 'none', |
| 19 | + condition: 'Normal', |
| 20 | + }, |
| 21 | + maiaEvaluations: [], |
| 22 | + stockfishEvaluations: [], |
| 23 | + tree: new GameTree(new Chess().fen()), |
| 24 | + type: 'play', |
| 25 | +}) |
| 26 | + |
| 27 | +interface Props { |
| 28 | + analyzedGame: AnalyzedGame | null |
| 29 | + analysisEnabled: boolean |
| 30 | + onToggleAnalysis: () => void |
| 31 | +} |
| 32 | + |
| 33 | +export const OpeningDrillAnalysis: React.FC<Props> = ({ |
| 34 | + analyzedGame, |
| 35 | + analysisEnabled, |
| 36 | + onToggleAnalysis, |
| 37 | +}) => { |
| 38 | + // Always call the hook but use mock data when disabled |
| 39 | + const analysisController = useAnalysisController( |
| 40 | + analyzedGame || createMockAnalyzedGame(), |
| 41 | + 'white', |
| 42 | + ) |
| 43 | + const mockHover = () => { |
| 44 | + // No-op for disabled analysis |
| 45 | + } |
| 46 | + |
| 47 | + const mockMakeMove = () => { |
| 48 | + // No-op for disabled analysis |
| 49 | + } |
| 50 | + |
| 51 | + const mockSetHoverArrow = () => { |
| 52 | + // No-op for disabled analysis |
| 53 | + } |
| 54 | + |
| 55 | + return ( |
| 56 | + <div className="flex h-[calc(55vh+4.5rem)] w-full flex-col gap-2"> |
| 57 | + {/* Analysis Toggle */} |
| 58 | + <div className="flex items-center justify-between rounded bg-background-1 px-4 py-2"> |
| 59 | + <div className="flex items-center gap-2"> |
| 60 | + <span className="material-symbols-outlined text-xl">analytics</span> |
| 61 | + <h3 className="font-semibold">Analysis</h3> |
| 62 | + </div> |
| 63 | + <button |
| 64 | + onClick={onToggleAnalysis} |
| 65 | + className={`flex items-center gap-2 rounded px-3 py-1 text-sm transition-colors ${ |
| 66 | + analysisEnabled |
| 67 | + ? 'bg-human-4 text-white hover:bg-human-4/80' |
| 68 | + : 'bg-background-2 text-secondary hover:bg-background-3' |
| 69 | + }`} |
| 70 | + > |
| 71 | + <span className="material-symbols-outlined text-sm"> |
| 72 | + {analysisEnabled ? 'visibility' : 'visibility_off'} |
| 73 | + </span> |
| 74 | + {analysisEnabled ? 'Enabled' : 'Disabled'} |
| 75 | + </button> |
| 76 | + </div> |
| 77 | + |
| 78 | + {/* Top Row - Highlight Component */} |
| 79 | + <div className="relative"> |
| 80 | + <div className="flex h-[calc((55vh+4.5rem)/2)]"> |
| 81 | + <Highlight |
| 82 | + hover={mockHover} |
| 83 | + makeMove={mockMakeMove} |
| 84 | + currentMaiaModel="maia_kdd_1500" |
| 85 | + recommendations={analysisController.moveRecommendations} |
| 86 | + moveEvaluation={ |
| 87 | + analysisController.moveEvaluation || { |
| 88 | + maia: undefined, |
| 89 | + stockfish: undefined, |
| 90 | + } |
| 91 | + } |
| 92 | + movesByRating={analysisController.movesByRating} |
| 93 | + colorSanMapping={analysisController.colorSanMapping} |
| 94 | + boardDescription={ |
| 95 | + analysisEnabled |
| 96 | + ? 'This position offers multiple strategic options. Consider central control and piece development.' |
| 97 | + : 'Analysis is disabled. Enable analysis to see detailed move evaluations and recommendations.' |
| 98 | + } |
| 99 | + /> |
| 100 | + </div> |
| 101 | + {!analysisEnabled && ( |
| 102 | + <div className="absolute inset-0 z-10 flex items-center justify-center overflow-hidden rounded bg-background-1/80 backdrop-blur-sm"> |
| 103 | + <div className="rounded bg-background-2/90 p-4 text-center shadow-lg"> |
| 104 | + <span className="material-symbols-outlined mb-2 text-3xl text-human-3"> |
| 105 | + lock |
| 106 | + </span> |
| 107 | + <p className="font-medium text-primary">Analysis Disabled</p> |
| 108 | + <p className="text-sm text-secondary"> |
| 109 | + Enable analysis to see move evaluations |
| 110 | + </p> |
| 111 | + </div> |
| 112 | + </div> |
| 113 | + )} |
| 114 | + </div> |
| 115 | + |
| 116 | + {/* Bottom Row - Move Map and Blunder Meter */} |
| 117 | + <div className="relative"> |
| 118 | + <div className="flex h-[calc((55vh+4.5rem)/2)] flex-row gap-2"> |
| 119 | + <div className="flex h-full w-full flex-col"> |
| 120 | + <MoveMap |
| 121 | + moveMap={analysisController.moveMap} |
| 122 | + colorSanMapping={analysisController.colorSanMapping} |
| 123 | + setHoverArrow={mockSetHoverArrow} |
| 124 | + /> |
| 125 | + </div> |
| 126 | + <BlunderMeter |
| 127 | + hover={mockHover} |
| 128 | + makeMove={mockMakeMove} |
| 129 | + data={analysisController.blunderMeter} |
| 130 | + colorSanMapping={analysisController.colorSanMapping} |
| 131 | + /> |
| 132 | + </div> |
| 133 | + {!analysisEnabled && ( |
| 134 | + <div className="absolute inset-0 z-10 flex items-center justify-center overflow-hidden rounded bg-background-1/80 backdrop-blur-sm"> |
| 135 | + <div className="rounded bg-background-2/90 p-4 text-center shadow-lg"> |
| 136 | + <span className="material-symbols-outlined mb-2 text-3xl text-human-3"> |
| 137 | + lock |
| 138 | + </span> |
| 139 | + <p className="font-medium text-primary">Analysis Disabled</p> |
| 140 | + <p className="text-sm text-secondary"> |
| 141 | + Enable analysis to see position evaluation |
| 142 | + </p> |
| 143 | + </div> |
| 144 | + </div> |
| 145 | + )} |
| 146 | + </div> |
| 147 | + </div> |
| 148 | + ) |
| 149 | +} |
0 commit comments