import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Download, Server, LogOut, ChevronDown, Tag } from 'lucide-react'; import { toast } from 'sonner'; import { toPng } from 'html-to-image'; import { useReactFlow } from '@xyflow/react'; import { Button } from '../ui/Button'; import { useAuthStore } from '../../store/useAuthStore'; import type { ServiceMapSummary } from '../../types'; import { apiClient } from '../../api/client'; interface MapToolbarProps { maps: ServiceMapSummary[]; activeMapId: string | null; activeMapName: string; onSelectMap: (id: string) => void; onCreateMap: () => void; onPopulate: () => void; flowContainerRef: React.RefObject; } export function MapToolbar({ maps, activeMapId, activeMapName, onSelectMap, onCreateMap, onPopulate, flowContainerRef, }: MapToolbarProps) { const navigate = useNavigate(); const { logout } = useAuthStore(); const { fitView } = useReactFlow(); const [exporting, setExporting] = useState(false); const [mapDropdownOpen, setMapDropdownOpen] = useState(false); async function handleExport() { if (!flowContainerRef.current) return; setExporting(true); const toastId = toast.loading('Exporting…'); // Temporarily hide React Flow UI chrome const minimap = flowContainerRef.current.querySelector('.react-flow__minimap') as HTMLElement | null; const controls = flowContainerRef.current.querySelector('.react-flow__controls') as HTMLElement | null; if (minimap) minimap.style.display = 'none'; if (controls) controls.style.display = 'none'; try { const dataUrl = await toPng(flowContainerRef.current, { cacheBust: true }); const link = document.createElement('a'); link.download = `rackmapper-map-${activeMapName.replace(/\s+/g, '-')}-${Date.now()}.png`; link.href = dataUrl; link.click(); toast.success('Exported', { id: toastId }); } catch { toast.error('Export failed', { id: toastId }); } finally { if (minimap) minimap.style.display = ''; if (controls) controls.style.display = ''; setExporting(false); } } async function handleLogout() { await logout(); navigate('/login', { replace: true }); } return (
{/* Left */}
RACKMAPPER
Service Mapper {/* Map selector */}
{mapDropdownOpen && (
{maps.map((m) => ( ))}
)}
{/* Right */}
{activeMapId && ( <> )}
); }