/** * This file is part of the SplendidBear Websites' projects. * * Copyright (c) 2026 @ www.splendidbear.org * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import React, { Fragment, useState } from 'react'; import { useGame } from '@mine-contexts'; import GridField from './GridField'; import UserControl from '../user/UserControl'; import GameTimer from '../GameTimer'; import { BOMB_SYMBOLS, bombRadius } from '@mine-utils'; const GridControl = ({ gameAssoc, onClick, resign }) => { const { overlay, overlayTitle, overlaySubTitle, webPlayer, activePlayer, bombSelected, cells, setCells, endRef, } = useGame(); const [copied, setCopied] = useState(false); const shareUrl = gameAssoc ? `${window.location.origin}/battle/${gameAssoc}` : null; const handleShare = () => { if (!shareUrl) return; navigator.clipboard.writeText(shareUrl).then(() => { setCopied(true); setTimeout(() => setCopied(false), 2200); }); }; const handleHover = (row, col) => { if (!bombSelected) return; const activeColor = activePlayer ? 'blue' : 'red'; if (activeColor !== webPlayer) return; setCells(prev => { const next = prev.map(r => r.map(c => null !== c.bombTargetArea ? { ...c, bombTargetArea: null } : c, )); bombRadius(row, col, prev.length, prev[0]?.length ?? 0).forEach(([r, c], i) => { if (!next[r]?.[c]) return; next[r] = [...next[r]]; next[r][c] = { ...next[r][c], bombTargetArea: BOMB_SYMBOLS[i] }; }); return next; }); }; return (

{overlayTitle}

{'string' === typeof overlaySubTitle ? (

{overlaySubTitle}

) : ( overlaySubTitle )} {gameAssoc && endRef.current && ( )}
{cells.flatMap((row, r) => row.map((cell, c) => ( onClick([r, c])} onMouseEnter={() => handleHover(r, c)} /> )), )}
); }; export default GridControl;