import { useEffect } from 'react';
import IconButton from '@mui/material/IconButton';
import CloseIcon from '@mui/icons-material/Close';
import { useScryfallCard } from '@app/hooks';
import type { Data } from '@app/types';
import { useZoneViewDialog } from './useZoneViewDialog';
import './ZoneViewDialog.css';
export interface ZoneViewDialogProps {
isOpen: boolean;
gameId: number | undefined;
playerId: number | undefined;
zoneName: string | undefined;
handleClose: () => void;
initialPosition?: { x: number; y: number };
}
function ZoneThumbnail({ card }: { card: Data.ServerInfo_Card }) {
const { smallUrl } = useScryfallCard(card);
return (
{smallUrl && !card.faceDown ? (

) : (
{card.faceDown ? 'Face Down' : card.name}
)}
);
}
const DEFAULT_POSITION = { x: 80, y: 80 };
function ZoneViewDialog({
isOpen,
gameId,
playerId,
zoneName,
handleClose,
initialPosition = DEFAULT_POSITION,
}: ZoneViewDialogProps) {
const { cards, count, title, position, handlePointerDown, handlePointerMove, handlePointerUp } =
useZoneViewDialog({ gameId, playerId, zoneName, initialPosition });
useEffect(() => {
if (!isOpen) {
return;
}
const onKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
handleClose();
}
};
window.addEventListener('keydown', onKeyDown);
return () => window.removeEventListener('keydown', onKeyDown);
}, [isOpen, handleClose]);
if (!isOpen) {
return null;
}
return (
{title}
{cards.length === 0 ? (
{count > 0
? `${count} hidden card${count === 1 ? '' : 's'}`
: 'This zone is empty.'}
) : (
{cards.map((card) => (
))}
)}
);
}
export default ZoneViewDialog;