import React, { useState, useEffect } from 'react'; const PuzzleGrid = ({ grid, clues, showSolution, onCellChange }) => { const [userAnswers, setUserAnswers] = useState({}); useEffect(() => { setUserAnswers({}); }, [grid]); const handleCellInput = (row, col, value) => { const key = `${row}-${col}`; const newAnswers = { ...userAnswers, [key]: value.toUpperCase() }; setUserAnswers(newAnswers); onCellChange && onCellChange(row, col, value); }; const getCellValue = (row, col) => { if (showSolution && !isBlackCell(row, col)) { return grid[row][col]; } const key = `${row}-${col}`; return userAnswers[key] || ''; }; const isBlackCell = (row, col) => { return grid[row][col] === '.'; }; const getCellNumber = (row, col) => { if (!clues) return null; const clue = clues.find(c => c.position.row === row && c.position.col === col); return clue ? clue.number : null; }; if (!grid || grid.length === 0) { return