import React, { useState } from 'react'; import { Maximize2, Network, ArrowRight, ArrowLeft, ArrowLeftRight, RotateCcw, Loader2, HelpCircle, Palette, ChevronUp, ChevronDown, ChevronLeft, ChevronRight, ZoomIn, ZoomOut, Crosshair, } from 'lucide-react'; import type { GraphMode } from './types'; interface GraphToolbarProps { mode: GraphMode; traceDir: 'forward' | 'backward' | 'both'; focusNode: string | null; loading: boolean; nodeCount: number; edgeCount: number; onFitView: () => void; onReset: () => void; onTraceForward: () => void; onTraceBackward: () => void; onTraceBoth: () => void; onNeighbors: () => void; onPanUp: () => void; onPanDown: () => void; onPanLeft: () => void; onPanRight: () => void; onZoomIn: () => void; onZoomOut: () => void; onCenterGraph: () => void; } interface ToolButtonProps { onClick: () => void; active?: boolean; disabled?: boolean; title: string; children: React.ReactNode; variant?: 'default' | 'danger'; } const ToolButton: React.FC = ({ onClick, active, disabled, title, children, variant = 'default', }) => { const base = 'flex items-center gap-1.5 px-2.5 py-1.5 rounded text-[10px] font-mono font-semibold transition-all border'; const inactive = 'bg-canvas border-border text-text-muted hover:text-text hover:border-primary/50'; const activeStyle = 'bg-primary/10 border-primary text-primary'; const dangerStyle = 'bg-red-500/10 border-red-500/30 text-red-400 hover:bg-red-500/20'; const disabledStyle = 'opacity-40 cursor-not-allowed'; const cls = [ base, disabled ? disabledStyle : variant === 'danger' ? dangerStyle : active ? activeStyle : inactive, ].join(' '); return ( ); }; const NODE_LEGEND = [ { label: 'Module', color: '#5e6ad2' }, { label: 'Service', color: '#10b981' }, { label: 'Utility', color: '#f59e0b' }, { label: 'Config', color: '#9ca0a8' }, { label: 'Test', color: '#3b82f6' }, ]; const SHORTCUTS = [ { key: 'F', desc: 'Fit view' }, { key: 'R', desc: 'Reset graph' }, { key: 'Scroll', desc: 'Zoom in / out' }, { key: '↑ ↓ ← →', desc: 'Pan canvas' }, { key: 'Click node', desc: 'Select & inspect' }, ]; export const GraphToolbar: React.FC = ({ mode, traceDir, focusNode, loading, nodeCount, edgeCount, onFitView, onReset, onTraceForward, onTraceBackward, onTraceBoth, onNeighbors, onPanUp, onPanDown, onPanLeft, onPanRight, onZoomIn, onZoomOut, onCenterGraph, }) => { const hasFocus = Boolean(focusNode); const focusLabel = focusNode ? focusNode.split('/').pop() ?? focusNode : null; const [showLegend, setShowLegend] = useState(false); const [showShortcuts, setShowShortcuts] = useState(false); return (
{/* Left — interaction mode buttons */}
Expand Deps → ← Users Both
{/* Divider */}
{/* View controls */}
Fit Reset
{/* Divider */}
{/* Viewport Pan/Zoom Controls */}
{/* Divider */}
{/* Legend + shortcuts */}
setShowLegend(v => !v)} active={showLegend} title="Toggle node colour legend"> Legend setShowShortcuts(v => !v)} active={showShortcuts} title="Keyboard shortcuts"> Keys
{/* Status / focus indicator */}
{loading && ( Loading… )} {focusLabel && !loading && ( ⬤ {focusLabel} )} {!loading && ( {nodeCount}n · {edgeCount}e )}
{/* Legend dropdown */} {showLegend && (

Node Categories

{NODE_LEGEND.map(({ label, color }) => (
{label}
))}
)} {/* Shortcuts dropdown */} {showShortcuts && (

Keyboard Shortcuts

{SHORTCUTS.map(({ key, desc }) => (
{key}
{desc}
))}
)}
); };