// ============================================================
// ContextMenu — 可复用右键菜单封装
//
// 用法：
//   <ContextMenu items={[{ label: '新建项目', onClick: () => ... }]}>
//       <YourComponent />
//   </ContextMenu>
// ============================================================

import { type ReactNode } from 'react';
import { Dropdown, type MenuProps } from 'antd';

export interface ContextMenuItem {
    label: string;
    onClick: () => void;
    disabled?: boolean;
    danger?: boolean;
}

interface ContextMenuProps {
    items: ContextMenuItem[];
    children: ReactNode;
}

export function ContextMenu({ items, children }: ContextMenuProps) {
    const menuItems: MenuProps['items'] = items.map((item, i) => ({
        key: String(i),
        label: item.label,
        onClick: item.onClick,
        disabled: item.disabled,
        danger: item.danger,
    }));

    return (
        <Dropdown menu={{ items: menuItems }} trigger={['contextMenu']}>
            {children}
        </Dropdown>
    );
}
