import React from 'react';
import useFlowStore from '../store/flowStore';

interface ContextMenuProps {
  x: number;
  y: number;
  items: { label: string; onClick: () => void; danger?: boolean }[];
  onClose: () => void;
}

export const ContextMenu: React.FC<ContextMenuProps> = ({ x, y, items, onClose }) => {
  const { theme } = useFlowStore();
  const isDark = theme === 'dark';

  return (
    <div 
      className={`fixed z-50 shadow-lg rounded-md py-1 min-w-[150px] ${
        isDark 
          ? 'bg-gray-800 border border-gray-600' 
          : 'bg-white border border-gray-200'
      }`}
      style={{ top: y, left: x }}
      onClick={(e) => e.stopPropagation()}
    >
      {items.map((item, idx) => (
        <button
          key={idx}
          className={`w-full text-left px-4 py-2 text-sm transition-colors ${
            item.danger 
              ? isDark 
                ? 'text-red-400 hover:bg-red-900/50' 
                : 'text-red-600 hover:bg-red-50'
              : isDark 
                ? 'text-gray-200 hover:bg-gray-700' 
                : 'text-gray-700 hover:bg-gray-100'
          }`}
          onClick={() => {
            item.onClick();
            onClose();
          }}
        >
          {item.label}
        </button>
      ))}
    </div>
  );
};

