// Spectator Settings // Purpose: Provides a shared gear menu for page-defined spectator options. // Scope: Pages supply their options and own preference persistence. import { useEffect, useRef, useState } from 'react'; import { FaCog } from 'react-icons/fa'; import CardFrame from '../CardFrame/index.jsx'; export default function SpectatorSettings({ options, preferences, onToggle }) { const [open, setOpen] = useState(false); const controlsRef = useRef(null); useEffect(() => { if (!open) return undefined; const handlePointerDown = (event) => { /* The popup floats above both the sidebar and camera grid, so clicking elsewhere should dismiss it without changing any saved preference. Keeping the gear and popup under one ref makes clicks on either safe. */ if (!controlsRef.current?.contains(event.target)) setOpen(false); }; const handleKeyDown = (event) => { // Escape mirrors normal dialog/menu behavior without trapping keyboard focus. if (event.key === 'Escape') setOpen(false); }; document.addEventListener('pointerdown', handlePointerDown); document.addEventListener('keydown', handleKeyDown); return () => { document.removeEventListener('pointerdown', handlePointerDown); document.removeEventListener('keydown', handleKeyDown); }; }, [open]); return (
{open ? (
{options.map((option) => ( ))}
) : null}
); }