"use client"; import { useState } from "react"; import { generateSudoku, solveSudoku, Difficulty, SudokuGrid } from "./sudokuGenerator"; function cloneGrid(grid: SudokuGrid): SudokuGrid { return grid.map(row => [...row]); } function getInvalidCells(grid: SudokuGrid): boolean[][] { const invalid: boolean[][] = Array.from({ length: 9 }, () => Array(9).fill(false)); for (let row = 0; row < 9; row++) { for (let col = 0; col < 9; col++) { const val = grid[row][col]; if (val === 0) continue; for (let k = 0; k < 9; k++) { if (k !== col && grid[row][k] === val) invalid[row][col] = true; if (k !== row && grid[k][col] === val) invalid[row][col] = true; } const startRow = row - row % 3; const startCol = col - col % 3; for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { const r = startRow + i; const c = startCol + j; if ((r !== row || c !== col) && grid[r][c] === val) invalid[row][col] = true; } } } } return invalid; } function SudokuBoard({ grid, onChange, editable, invalidCells, fixedCells }: { grid: SudokuGrid; onChange?: (row: number, col: number, value: number) => void; editable?: boolean; invalidCells?: boolean[][]; fixedCells?: boolean[][] }) { return (
| {editable && onChange ? ( fixedCells && fixedCells[i][j] ? ( {cell} ) : ( onChange(i, j, Number(e.target.value))} style={{width:'100%',height:'100%',textAlign:'center',background:'#fff',border:'none',outline:'none',fontSize:20,fontWeight:'bold',color:invalidCells && invalidCells[i][j] ? '#d32f2f' : '#222'}} /> ) ) : ( cell !== 0 ? ( {cell} ) : "" )} | ))}