import { useState, useCallback } from "react"; import { Play, Pause, AlertCircle, Loader2 } from "lucide-react"; import type { ProjectStatus } from "@fusion/core"; import type { ProjectHealth } from "../api"; export interface ProjectHealthBadgeProps { status: ProjectStatus; health?: ProjectHealth | null; size?: "sm" | "md" | "lg"; showTooltip?: boolean; } const STATUS_CONFIG: Record = { active: { label: "Active", color: "var(--success)", icon: Play }, paused: { label: "Paused", color: "var(--warning)", icon: Pause }, errored: { label: "Error", color: "var(--color-error)", icon: AlertCircle }, initializing: { label: "Initializing", color: "var(--info)", icon: Loader2 }, }; /** * ProjectHealthBadge - Color-coded badge showing project health status * * Displays a status indicator with icon and label. Optionally shows a tooltip * with detailed health metrics on hover. */ export function ProjectHealthBadge({ status, health, size = "md", showTooltip = true, }: ProjectHealthBadgeProps) { const [isHovered, setIsHovered] = useState(false); const config = STATUS_CONFIG[status]; const StatusIcon = config.icon; const handleMouseEnter = useCallback(() => { if (showTooltip && health) { setIsHovered(true); } }, [showTooltip, health]); const handleMouseLeave = useCallback(() => { setIsHovered(false); }, []); const sizeClasses = { sm: "project-health-badge--sm", md: "project-health-badge--md", lg: "project-health-badge--lg", }; const isInitializing = status === "initializing"; return (
{config.label} {/* Tooltip with health metrics */} {isHovered && health && (
Health Metrics
Active Tasks: {health.activeTaskCount}
In-Flight Agents: {health.inFlightAgentCount}
Completed: {health.totalTasksCompleted}
Failed: {health.totalTasksFailed}
{health.lastErrorMessage && (
Last Error: {health.lastErrorMessage}
)}
)}
); }