import { Badge, Box, Flex, HStack, Icon, Progress, SimpleGrid, Stack, Text } from '@chakra-ui/react'
import type { ComponentState, DemoDetails } from '../lib/api'
import { podStatusColor, podStatusLabel } from '../lib/format'
export const PODSTATUS_COMPONENTS: { key: keyof DemoDetails['state']; label: string }[] = [
{ key: 'api', label: 'Backend' },
{ key: 'web', label: 'Frontend' },
{ key: 'db', label: 'PostgreSQL' },
{ key: 'dbm', label: 'Redis' },
]
// PodStatusPanel : vue d'ensemble des 4 composants d'une démo (statut + CPU/mémoire live).
export function PodStatusPanel({ state }: { state: DemoDetails['state'] }) {
const allRunning = PODSTATUS_COMPONENTS.every((c) => state[c.key].phase === 'Running')
const downCount = PODSTATUS_COMPONENTS.filter((c) => state[c.key].phase !== 'Running').length
return (
{allRunning
? 'Tous les services sont opérationnels'
: `${downCount} service${downCount > 1 ? 's' : ''} indisponible${downCount > 1 ? 's' : ''}`}
{/* 1 colonne jusqu'à lg : à "sm" (480px), 2 colonnes serraient trop les
cartes (CPU/mémoire en mono + badge) et forçaient un débordement
horizontal — surtout dans le contexte carte mobile, déjà à l'étroit
avec son propre padding. */}
{PODSTATUS_COMPONENTS.map((c) => (
))}
)
}
function ComponentCard({ title, cs }: { title: string; cs: ComponentState }) {
const cpuPct = cs.cpu_limit_milli > 0 ? Math.min(100, Math.round((cs.cpu_milli / cs.cpu_limit_milli) * 100)) : 0
const memPct = cs.memory_limit_mi > 0 ? Math.min(100, Math.round((cs.memory_mi / cs.memory_limit_mi) * 100)) : 0
return (
{title}
{podStatusLabel(cs.phase)}
CPU
{cs.cpu_milli}m / {cs.cpu_limit_milli}m
Mémoire
{cs.memory_mi}Mi / {cs.memory_limit_mi}Mi
)
}
export function ChevronIcon(props: React.ComponentProps) {
return (
)
}