import { useMemo } from 'react' import { Card, CardContent, CardHeader } from '@/components/ui/card' import { DotMatrixText } from '@/components/ui/dot-matrix' import { Cpu, MemoryStick, HardDrive, Clock, Server, Box } from 'lucide-react' import type { ProxmoxNode, ProxmoxVM } from '@/types/proxmox' import { formatBytes, formatUptime } from '@/lib/format' import { cn } from '@/lib/utils' interface NodeHealthGridProps { nodes: ProxmoxNode[] | undefined vms: ProxmoxVM[] | undefined } function getStatusColor(status: 'online' | 'offline'): string { return status === 'online' ? 'bg-success shadow-[0_0_6px] shadow-success/60' : 'bg-destructive' } function getStatusTextColor(status: 'online' | 'offline'): string { return status === 'online' ? 'text-success' : 'text-destructive' } function NodeCard({ node, vmCount }: { node: ProxmoxNode; vmCount: number }) { const cpuPercent = node.maxcpu > 0 ? node.cpu : 0 const memPercent = node.maxmem > 0 ? node.mem / node.maxmem : 0 const diskPercent = node.maxdisk > 0 ? node.disk / node.maxdisk : 0 return ( {node.node} {(cpuPercent * 100).toFixed(0)}% {(memPercent * 100).toFixed(0)}% {(diskPercent * 100).toFixed(0)}% {formatUptime(node.uptime)} {vmCount} VMs {formatBytes(node.disk)} ) } export function NodeHealthGrid({ nodes, vms }: NodeHealthGridProps) { const vmCounts = useMemo(() => { const counts: Record = {} vms?.forEach((vm) => { counts[vm.node] = (counts[vm.node] ?? 0) + 1 }) return counts }, [vms]) if (!nodes || nodes.length === 0) { return ( No nodes available ) } return ( {nodes.map((node) => ( ))} ) }
No nodes available