import { useState } from 'react' import { RotateCcw } from 'lucide-react' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { EDGE_TYPE_LABELS, type EdgeData, type EdgePathStyle, type EdgeType } from '@/types' import { EDGE_DEFAULT_COLORS } from '@/utils/edgeColors' const EDGE_TYPES = Object.entries(EDGE_TYPE_LABELS) as [EdgeType, string][] interface EdgeModalProps { open: boolean onClose: () => void onSubmit: (data: EdgeData) => void onDelete?: () => void initial?: Partial title?: string } export function EdgeModal({ open, onClose, onSubmit, onDelete, initial, title = 'Connect Nodes' }: EdgeModalProps) { const [type, setType] = useState(initial?.type ?? 'ethernet') const [label, setLabel] = useState(initial?.label ?? '') const [vlanId, setVlanId] = useState(initial?.vlan_id?.toString() ?? '') const [customColor, setCustomColor] = useState(initial?.custom_color) const [pathStyle, setPathStyle] = useState(initial?.path_style ?? 'bezier') const [animated, setAnimated] = useState(initial?.animated ?? false) const effectiveColor = customColor ?? EDGE_DEFAULT_COLORS[type] const handleSubmit = (e: React.FormEvent) => { e.preventDefault() onSubmit({ type, label: label || undefined, vlan_id: type === 'vlan' && vlanId ? parseInt(vlanId) : undefined, custom_color: customColor, path_style: pathStyle, animated: animated || undefined, }) onClose() } const handleDelete = () => { onDelete?.() onClose() } return ( !o && onClose()}> {title}
{type === 'vlan' && (
setVlanId(e.target.value)} placeholder="e.g. 20" className="bg-[#21262d] border-[#30363d] font-mono text-sm h-8" />
)}
setLabel(e.target.value)} placeholder="e.g. 1G, trunk..." className="bg-[#21262d] border-[#30363d] text-sm h-8" />
{(['bezier', 'smooth'] as EdgePathStyle[]).map((style) => ( ))}
{customColor && ( )}
) }