import Menu from '@mui/material/Menu'; import MenuItem from '@mui/material/MenuItem'; import Divider from '@mui/material/Divider'; import Check from '@mui/icons-material/Check'; import { useWebClient } from '@app/hooks'; import { GameSelectors, useAppSelector } from '@app/store'; import { App } from '@app/types'; import './ZoneContextMenu.css'; export interface ZoneContextMenuProps { isOpen: boolean; anchorPosition: { top: number; left: number } | null; gameId: number; playerId: number | null; zoneName: string | null; onClose: () => void; onRequestDrawN: () => void; onRequestDumpN: () => void; onRequestRevealTopN: () => void; onRequestRevealZone: () => void; } function ZoneContextMenu({ isOpen, anchorPosition, gameId, playerId, zoneName, onClose, onRequestDrawN, onRequestDumpN, onRequestRevealTopN, onRequestRevealZone, }: ZoneContextMenuProps) { const webClient = useWebClient(); const zone = useAppSelector((state) => playerId != null && zoneName != null ? GameSelectors.getZone(state, gameId, playerId, zoneName) : undefined, ); if (playerId == null || zoneName == null) { return null; } const game = webClient.request.game; const alwaysReveal = zone?.alwaysRevealTopCard ?? false; const alwaysLook = zone?.alwaysLookAtTopCard ?? false; // Close-then-act helpers (avoid duplicating onClose at every site). const run = (fn: () => void) => () => { fn(); onClose(); }; const handleDrawOne = () => { game.drawCards(gameId, { number: 1 }); }; const handleShuffle = () => { game.shuffle(gameId, { zoneName: App.ZoneName.DECK, start: 0, end: -1 }); }; const handleRevealTop = () => { game.revealCards(gameId, { zoneName: App.ZoneName.DECK, playerId: -1, topCards: 1, }); }; const handleToggleAlwaysReveal = () => { game.changeZoneProperties(gameId, { zoneName: App.ZoneName.DECK, alwaysRevealTopCard: !alwaysReveal, }); }; const handleToggleAlwaysLook = () => { game.changeZoneProperties(gameId, { zoneName: App.ZoneName.DECK, alwaysLookAtTopCard: !alwaysLook, }); }; const menuItems: React.ReactNode[] = []; if (zoneName === App.ZoneName.DECK) { menuItems.push( Draw a card, Draw N cards…, Shuffle, Dump top N…, , Reveal top card to all , Reveal top N to… , , {alwaysReveal ? : null} Always reveal top card , {alwaysLook ? : null} Always look at top card , ); } else if (zoneName === App.ZoneName.GRAVE) { menuItems.push( Reveal graveyard to… , ); } else if (zoneName === App.ZoneName.EXILE) { menuItems.push( Reveal exile to… , ); } else { return null; } return ( {menuItems} ); } export default ZoneContextMenu;