import { jsx } from "react/jsx-runtime";
import { memo, useCallback, useState } from "react";
import { CanvasDropdownMenu } from "../shared/CanvasDropdownMenu.js";
import { MenuButton } from "./NodeContextMenu.styles.js";
const NodeContextMenu = /*#__PURE__*/ memo(({ menuItems, isVisible = false })=>{
    const [isOpen, setIsOpen] = useState(false);
    const handleMenuItemClick = useCallback((item)=>{
        if (true === item.disabled) return;
        item.onClick();
        setIsOpen(false);
    }, []);
    if (!menuItems || 0 === menuItems.length) return null;
    if (!isVisible && !isOpen) return null;
    return /*#__PURE__*/ jsx(MenuButton, {
        $isVisible: isVisible || isOpen,
        onClick: (e)=>e.stopPropagation(),
        onMouseDown: (e)=>e.stopPropagation(),
        children: /*#__PURE__*/ jsx(CanvasDropdownMenu, {
            open: isOpen,
            onOpenChange: setIsOpen,
            menuItems: menuItems,
            onItemClick: handleMenuItemClick,
            triggerAriaLabel: "Node context menu"
        })
    });
});
export { NodeContextMenu };
