"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo } from "react";
import { cn } from "@stigmer/theme";
/**
 * Compact status badge rendered at the top-right corner of a workflow node
 * in execution mode. Provides text/icon differentiation beyond color alone
 * (WCAG 1.4.1 compliance).
 *
 * For fork nodes, displays branch completion progress (e.g. "1/3") when
 * the fork is running and `forkProgress` is provided (T06).
 *
 * Uses the same positioning pattern as the validation error badge in
 * `WorkflowNode.tsx`.
 */
export const ExecutionBadge = memo(function ExecutionBadge({ status, attemptNumber, forkProgress, approvalToolName, agentActivity, }) {
    if (status === "not_reached" || status === "pending")
        return null;
    // Approval-specific badge: show tool name when available.
    if (status === "waiting_approval" && approvalToolName) {
        const approvalLabel = `Awaiting approval: ${approvalToolName}`;
        return (_jsxs("span", { className: cn("absolute -right-1.5 -top-1.5 z-20 flex h-5 items-center gap-0.5 rounded-full px-1.5 text-[10px] font-semibold leading-none shadow-sm", "bg-[var(--stgm-warning,#f59e0b)] text-[var(--stgm-warning-foreground,#fff)]"), title: approvalLabel, "aria-label": approvalLabel, children: ["\u270B", _jsx("span", { className: "max-w-[60px] truncate", children: approvalToolName })] }));
    }
    // Agent activity badge: show what the agent is doing (tool name or message count).
    if (status === "running" && agentActivity && (agentActivity.currentToolName || agentActivity.messagesCount > 0)) {
        const displayText = agentActivity.currentToolName || `${agentActivity.messagesCount} msgs`;
        const agentLabel = agentActivity.currentToolName
            ? `Agent using tool: ${agentActivity.currentToolName}`
            : `Agent: ${agentActivity.messagesCount} messages, ${agentActivity.toolCallsCount} tool calls`;
        return (_jsxs("span", { className: cn("absolute -right-1.5 -top-1.5 z-20 flex h-5 items-center gap-0.5 rounded-full px-1.5 text-[10px] font-semibold leading-none shadow-sm", "bg-[var(--stgm-primary,#6366f1)] text-[var(--stgm-primary-foreground,#fff)]"), title: agentLabel, "aria-label": agentLabel, children: [agentActivity.currentToolName ? "🔧" : "💬", _jsx("span", { className: "max-w-[60px] truncate", children: displayText })] }));
    }
    // Fork-specific running badge: show branch progress instead of generic spinner.
    if (status === "running" && forkProgress) {
        const progressLabel = forkProgress.compete
            ? `Fork race, ${forkProgress.completed} of ${forkProgress.total} branches completed`
            : `Fork running, ${forkProgress.completed} of ${forkProgress.total} branches completed`;
        return (_jsxs("span", { className: cn("absolute -right-1.5 -top-1.5 z-20 flex h-5 min-w-5 items-center justify-center rounded-full px-1.5 text-[10px] font-semibold leading-none shadow-sm", "bg-[var(--stgm-primary,#6366f1)] text-[var(--stgm-primary-foreground,#fff)]"), title: progressLabel, "aria-label": progressLabel, children: [forkProgress.completed, "/", forkProgress.total, forkProgress.compete && _jsx("span", { className: "ml-0.5", children: "\u26A1" })] }));
    }
    const { icon, label, className } = BADGE_CONFIG[status];
    return (_jsxs("span", { className: cn("absolute -right-1.5 -top-1.5 z-20 flex h-5 min-w-5 items-center justify-center rounded-full px-1 text-[10px] font-semibold leading-none shadow-sm", className), title: label + (attemptNumber && attemptNumber > 1 ? ` (attempt ${attemptNumber})` : ""), "aria-label": label, children: [icon, status === "retrying" && attemptNumber != null && attemptNumber > 1 && (_jsx("span", { className: "ml-0.5", children: attemptNumber }))] }));
});
const BADGE_CONFIG = {
    running: {
        icon: "⟳",
        label: "Running",
        className: "bg-[var(--stgm-primary,#6366f1)] text-[var(--stgm-primary-foreground,#fff)]",
    },
    completed: {
        icon: "✓",
        label: "Completed",
        className: "bg-[var(--stgm-success,#22c55e)] text-[var(--stgm-success-foreground,#fff)]",
    },
    failed: {
        icon: "✕",
        label: "Failed",
        className: "bg-[var(--stgm-destructive,#ef4444)] text-[var(--stgm-destructive-foreground,#fff)]",
    },
    skipped: {
        icon: "—",
        label: "Skipped",
        className: "bg-[var(--stgm-muted,#e5e5e5)] text-[var(--stgm-muted-foreground,#737373)]",
    },
    retrying: {
        icon: "↻",
        label: "Retrying",
        className: "bg-[var(--stgm-warning,#f59e0b)] text-[var(--stgm-warning-foreground,#fff)]",
    },
    waiting_approval: {
        icon: "✋",
        label: "Waiting for approval",
        className: "bg-[var(--stgm-warning,#f59e0b)] text-[var(--stgm-warning-foreground,#fff)]",
    },
};
//# sourceMappingURL=ExecutionBadge.js.map