import { useState, useRef } from 'react'; import { System } from '@/lib/types'; interface SystemContextMenuProps { x: number; y: number; system: System; onRename: (newName: string) => void; onDelete: (system: System) => void; onClearConnections: (system: System) => void; onSetDestination?: (systemName: string, viaMode: boolean) => void; onClose: () => void; } export const SystemContextMenu = ({ x, y, system, onRename, onDelete, onClearConnections, onSetDestination, onClose }: SystemContextMenuProps) => { if (!system) { return null; } const [isRenaming, setIsRenaming] = useState(false); const [newName, setNewName] = useState(system.solarSystemName); const menuRef = useRef(null); const handleRename = () => { if (newName.trim() && newName !== system.solarSystemName) { onRename(newName); onClose(); } setIsRenaming(false); }; const handleSetDestinationClick = (e: React.MouseEvent) => { const via = !!e.shiftKey; if (typeof onSetDestination === 'function') { onSetDestination(system.solarSystemName, via); } else { console.error('onSetDestination not provided'); } onClose(); }; return (
e.stopPropagation()} > {isRenaming ? (
setNewName(e.target.value)} className="w-full px-2 py-1 bg-slate-700 border border-slate-600 rounded text-white" autoFocus onKeyDown={(e) => { if (e.key === 'Enter') handleRename(); if (e.key === 'Escape') setIsRenaming(false); }} />
) : (
)}
); };