'use client' import { useCallback, useEffect } from 'react' export type ContextMenuType = 'canvas' | 'node' | 'edge' type ContextMenuProps = { x: number y: number type: ContextMenuType onClose: () => void onAddDialogue?: () => void onAddChoice?: () => void onAddVariable?: () => void onDelete?: () => void onAddCondition?: () => void } export default function ContextMenu({ x, y, type, onClose, onAddDialogue, onAddChoice, onAddVariable, onDelete, onAddCondition, }: ContextMenuProps) { // Close menu on Escape key const handleKeyDown = useCallback( (e: KeyboardEvent) => { if (e.key === 'Escape') { onClose() } }, [onClose] ) // Close menu on click outside const handleClickOutside = useCallback(() => { onClose() }, [onClose]) useEffect(() => { document.addEventListener('keydown', handleKeyDown) document.addEventListener('click', handleClickOutside) return () => { document.removeEventListener('keydown', handleKeyDown) document.removeEventListener('click', handleClickOutside) } }, [handleKeyDown, handleClickOutside]) const menuItemClass = 'w-full px-4 py-2 text-left text-sm hover:bg-zinc-100 dark:hover:bg-zinc-700 cursor-pointer' return (