import { useEffect, useMemo, useState } from 'react' import { useNavigate } from 'react-router-dom' import { PieChart, Pie, Cell, ResponsiveContainer } from 'recharts' import { Plus, Server, Activity, AlertTriangle, CircleCheck, Box, MonitorSmartphone, Waypoints, AppWindow, type LucideIcon } from 'lucide-react' import { api, type Resource, type Integration, type Event } from '../lib/api' const subTabs = ['Overview'] const futureSubTabs = ['Network'] const cardBase: React.CSSProperties = { backgroundColor: 'rgba(10, 10, 12, 0.92)', border: '1px solid rgba(200, 164, 52, 0.08)', borderRadius: '12px', padding: '20px', boxShadow: '0 0 20px rgba(200, 164, 52, 0.03)', transition: 'border-color 0.2s ease', position: 'relative', overflow: 'hidden', height: '100%', display: 'flex', flexDirection: 'column', } const sectionTitle: React.CSSProperties = { fontSize: '11px', textTransform: 'uppercase', letterSpacing: '1.5px', color: '#7A7D85', fontWeight: 500, marginBottom: '16px', } function framedCard(bgUrl: string): React.CSSProperties { return { backgroundImage: `url(${bgUrl})`, backgroundSize: '100% 100%', backgroundPosition: 'center', backgroundRepeat: 'no-repeat', position: 'relative', overflow: 'hidden', height: '100%', display: 'flex', flexDirection: 'column', padding: '20px 20px 64px 20px', } } const cardVignette: React.CSSProperties = { position: 'absolute', inset: 0, pointerEvents: 'none', background: 'radial-gradient(ellipse closest-side at center, transparent 70%, var(--color-page) 100%)', } const cardDim: React.CSSProperties = { position: 'absolute', inset: 0, pointerEvents: 'none', backgroundColor: 'rgba(8, 8, 10, 0.45)', } const nodeStatusColor: Record = { healthy: '#2ECC71', warning: '#E67E22', critical: '#E74C3C', unknown: '#7A7D85', } const integrationPalette = ['#C8A434', '#E67E22', '#2ECC71', '#7A7D85', '#3B82F6', '#8B5E3C'] const kindIcon: Record = { vm: MonitorSmartphone, container: Box, app: AppWindow, host: Server, network: Waypoints, } function Donut({ data, centerLabel }: { data: { name: string; value: number; color: string }[]; centerLabel?: string }) { const hasData = data.some((d) => d.value > 0) return (
{hasData && ( {data.map((entry) => ( ))} )} {centerLabel && (
{centerLabel}
)}
{data.map((entry) => (
{entry.name} {entry.value}
))}
) } export default function Infrastructure() { const [activeTab, setActiveTab] = useState('Overview') const [resources, setResources] = useState(null) const [integrations, setIntegrations] = useState(null) const [events, setEvents] = useState(null) const [selectedNode, setSelectedNode] = useState(null) const navigate = useNavigate() useEffect(() => { api.listResources().then(({ resources }) => setResources(resources)) api.listIntegrations().then(({ integrations }) => setIntegrations(integrations)) api.listEvents(4).then(({ events }) => setEvents(events)) }, []) const healthy = resources?.filter((r) => r.status === 'healthy').length ?? 0 const warning = resources?.filter((r) => r.status === 'warning').length ?? 0 const critical = resources?.filter((r) => r.status === 'critical').length ?? 0 const total = resources?.length ?? 0 const statusCards = [ { label: 'Total Resources', value: String(total), icon: Server, sub: `${integrations?.filter((i) => i.status === 'connected').length ?? 0} integrations connected` }, { label: 'Healthy', value: String(healthy), icon: Activity, sub: total ? `${Math.round((healthy / total) * 100)}%` : '—', color: '#2ECC71' }, { label: 'Warnings', value: String(warning), icon: AlertTriangle, sub: warning ? 'Needs attention' : 'None', color: '#E67E22' }, { label: 'Critical', value: String(critical), icon: AlertTriangle, sub: critical ? 'Action required' : 'None', color: '#E74C3C' }, ] const distributionData = useMemo(() => { if (!resources) return [] const byIntegration = new Map() for (const r of resources) byIntegration.set(r.integration, (byIntegration.get(r.integration) ?? 0) + 1) return Array.from(byIntegration.entries()).map(([name, value], i) => ({ name, value, color: integrationPalette[i % integrationPalette.length] })) }, [resources]) return ( <> {/* Sub-tabs + Add Resource — hero banner is rendered at the layout level behind this */}
{subTabs.map((tab) => { const active = tab === activeTab return ( ) })} {futureSubTabs.map((tab) => ( ))}
{/* Status Cards */}
{statusCards.map((card) => { const Icon = card.icon return (

{card.label}

{card.value}

{card.sub}

) })}
{/* Middle Row */}
{/* Resource Distribution */}

Resource Distribution

{distributionData.length > 0 ? ( ) : (

Connect an integration in Settings to see resource distribution.

)}
{/* Node Status — expanded */}

Node Status

{resources && resources.length > 0 ? (
{resources.map((node, i) => { const NodeIcon = kindIcon[node.kind ?? ''] ?? Server return (
setSelectedNode(node)} className="cursor-pointer transition-colors" style={{ backgroundColor: selectedNode === node ? 'rgba(200,164,52,0.1)' : 'rgba(10, 10, 12, 0.55)', border: selectedNode === node ? '1px solid rgba(200,164,52,0.5)' : `1px solid ${nodeStatusColor[node.status]}33`, borderRadius: '8px', padding: '8px 10px', display: 'flex', flexDirection: 'column', gap: '6px', }} >
{node.name}
) })}
) : (

No resources reported yet. Connect Docker (or another supported integration) in Settings to populate this view.

)}
{/* Bottom Row */}
{/* Integration Health */}

Integration Health

{integrations && integrations.length > 0 ? (
{integrations.map((i) => (
{i.name} {i.status}
))}
) : (

No integrations added yet.

)}
{/* Node Detail — shows the node selected up in Node Status */}

Node Detail

{selectedNode ? (
{selectedNode.name}
{selectedNode.integration} | {selectedNode.status}
{selectedNode.detail && (

{selectedNode.detail}

)}
) : (

Select a node above to view its details.

)}
{/* Recent Activity */}

Recent Activity

{events && events.length > 0 ? (
{events.map((item) => (

{item.title}

))}
) : (

No activity yet.

)}
{/* Footer stats bar */}
{total} Resources| {integrations?.filter((i) => i.status === 'connected').length ?? 0} Integrations Connected {critical > 0 && ( <> | {critical} Critical )}
) }