import * as React from 'react' import { cn } from '@/lib/utils' export type SystemStatus = 'ACTIVE' | 'OFFLINE' | 'WARNING' | 'CRITICAL' | 'SCANNING' export interface SystemEntry { name: string status: SystemStatus /** Optional secondary text shown beside the name */ detail?: string } export interface StatusGridProps extends React.HTMLAttributes { systems: SystemEntry[] title?: string columns?: 1 | 2 | 3 } function statusColor(s: SystemStatus): string { switch (s) { case 'ACTIVE': return 'var(--color-green)' case 'OFFLINE': return 'var(--text-muted)' case 'WARNING': return 'var(--color-amber)' case 'CRITICAL': return 'var(--color-red)' case 'SCANNING': return 'var(--color-green)' } } function statusGlow(s: SystemStatus): string { switch (s) { case 'ACTIVE': return 'var(--glow-green)' case 'SCANNING': return 'var(--glow-green)' case 'WARNING': return 'var(--glow-amber)' case 'CRITICAL': return 'var(--glow-red)' default: return 'none' } } const StatusGrid = React.forwardRef( ({ className, systems, title, columns = 1, style, ...props }, ref) => { return (
{/* Header */} {title && (
{title}
)} {/* Grid of rows */}
{systems.map((system, i) => { const color = statusColor(system.status) const glow = statusGlow(system.status) const isScanning = system.status === 'SCANNING' // border logic: no bottom border on last row(s), no right on last column const totalRows = Math.ceil(systems.length / columns) const rowIndex = Math.floor(i / columns) const colIndex = i % columns const isLastRow = rowIndex === totalRows - 1 const isLastCol = colIndex === columns - 1 return (
{/* Name + optional detail */} {system.name} {system.detail && ( {system.detail} )} {/* Status dot + label */}
{system.status}
) })}
) } ) StatusGrid.displayName = 'StatusGrid' export { StatusGrid }