import { useState } from 'react' import modalStyles from './modal-interactive.module.css' 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][] type AnimMode = 'none' | 'basic' | 'snake' | 'flow' function toAnimMode(v: EdgeData['animated']): AnimMode { if (v === true || v === 'snake') return 'snake' if (v === 'flow') return 'flow' if (v === 'basic') return 'basic' return 'none' } interface EdgeModalProps { open: boolean onClose: () => void onSubmit: (data: EdgeData) => void onDelete?: () => void onClearWaypoints?: () => void initial?: Partial title?: string } export function EdgeModal({ open, onClose, onSubmit, onDelete, onClearWaypoints, 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 [animation, setAnimation] = useState(() => toAnimMode(initial?.animated)) 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: animation !== 'none' ? animation : 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 ${modalStyles['modal-radius']}`} />
)}
setLabel(e.target.value)} placeholder="e.g. 1G, trunk..." className={`bg-[#21262d] border-[#30363d] text-sm h-8 ${modalStyles['modal-radius']}`} />
{(['bezier', 'smooth'] as EdgePathStyle[]).map((style) => ( ))}
{(['none', 'basic', 'snake', 'flow'] as AnimMode[]).map((mode, i) => ( ))}
{customColor && ( )}
) }