"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo, useMemo } from "react";
/**
 * Decorative badge rendered below branch/container nodes in design mode.
 *
 * Shows contextual metadata:
 * - fork: branch name chips + join policy
 * - try_catch: catch handler indicator
 * - for_each: iteration info (concurrency, error policy)
 *
 * @since T09 (Branch Management UX)
 */
export const BranchBadge = memo(function BranchBadge({ kindString, config, }) {
    const raw = config;
    if (kindString === "fork") {
        return _jsx(ForkBadge, { config: raw });
    }
    if (kindString === "try_catch") {
        return _jsx(TryCatchBadge, { config: raw });
    }
    if (kindString === "for_each") {
        return _jsx(ForEachBadge, { config: raw });
    }
    return null;
});
// ---------------------------------------------------------------------------
function ForkBadge({ config }) {
    const branches = useMemo(() => {
        const raw = config.branches;
        if (!Array.isArray(raw))
            return [];
        return raw
            .filter((b) => b != null && typeof b === "object")
            .map((b) => b.name || "");
    }, [config.branches]);
    const compete = config.compete === true;
    if (branches.length === 0)
        return null;
    const maxVisible = 3;
    const visible = branches.slice(0, maxVisible);
    const overflow = branches.length > maxVisible ? branches.length - maxVisible : 0;
    return (_jsxs("div", { className: "absolute left-1/2 -translate-x-1/2 top-full mt-1 flex items-center gap-0.5 pointer-events-none", children: [visible.map((name) => (_jsx("span", { className: "rounded bg-[var(--stgm-muted,#f5f5f5)] border border-[var(--stgm-border,#e5e5e5)] px-1 py-px text-[8px] font-medium text-[var(--stgm-muted-foreground,#737373)] whitespace-nowrap", children: name }, name))), overflow > 0 && (_jsxs("span", { className: "text-[8px] text-[var(--stgm-muted-foreground,#737373)]", children: ["+", overflow] })), compete && (_jsx("span", { className: "ml-0.5 rounded bg-[var(--stgm-chart-amber,#f59e0b)]/10 border border-[var(--stgm-chart-amber,#f59e0b)]/30 px-1 py-px text-[8px] font-medium text-[var(--stgm-chart-amber,#f59e0b)] whitespace-nowrap", children: "race" }))] }));
}
function TryCatchBadge({ config }) {
    const catchBlock = config.catch;
    if (!catchBlock || typeof catchBlock !== "object")
        return null;
    const asVar = catchBlock.as;
    return (_jsx("div", { className: "absolute left-1/2 -translate-x-1/2 top-full mt-1 flex items-center gap-0.5 pointer-events-none", children: _jsxs("span", { className: "rounded bg-[var(--stgm-destructive,#ef4444)]/10 border border-[var(--stgm-destructive,#ef4444)]/20 px-1 py-px text-[8px] font-medium text-[var(--stgm-destructive,#ef4444)] whitespace-nowrap", children: ["catch: ", asVar || "error"] }) }));
}
function ForEachBadge({ config }) {
    const parallelism = config.max_parallelism || 0;
    const onError = config.on_error || "";
    const parts = [];
    if (parallelism > 0) {
        parts.push(`×${parallelism}`);
    }
    else {
        parts.push("seq");
    }
    const showErrorPolicy = parallelism > 0 && onError && onError !== "FOR_EACH_FAIL_FAST" && onError !== "FOR_EACH_ERROR_POLICY_UNSPECIFIED";
    return (_jsxs("div", { className: "absolute left-1/2 -translate-x-1/2 top-full mt-1 flex items-center gap-0.5 pointer-events-none", children: [_jsxs("span", { className: "rounded bg-[var(--stgm-muted,#f5f5f5)] border border-[var(--stgm-border,#e5e5e5)] px-1 py-px text-[8px] font-medium text-[var(--stgm-muted-foreground,#737373)] whitespace-nowrap", children: ["\u21BB ", parts.join(" ")] }), showErrorPolicy && (_jsx("span", { className: "rounded bg-[var(--stgm-chart-amber,#f59e0b)]/10 border border-[var(--stgm-chart-amber,#f59e0b)]/30 px-1 py-px text-[8px] font-medium text-[var(--stgm-chart-amber,#f59e0b)] whitespace-nowrap", children: onError === "FOR_EACH_CONTINUE" ? "continue" : "skip" }))] }));
}
//# sourceMappingURL=BranchBadge.js.map