"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo, useCallback } from "react";
import { cn } from "@stigmer/theme";
import { WaterfallBar } from "./WaterfallBar";
import { formatDuration, formatMicroUsd } from "../format-utils";
const BIGINT_ZERO = BigInt(0);
/**
 * A single row in the waterfall: task label on the left, bar on the right.
 *
 * Wrapped in `React.memo` so only the actively-running row re-renders
 * during live streaming (DD-010). Selection state is the primary
 * re-render trigger for completed rows.
 */
export const WaterfallRow = memo(function WaterfallRow({ entry, totalMs, nowMs, isSelected, onSelect, className, }) {
    const handleClick = useCallback(() => {
        onSelect(entry.taskName);
    }, [onSelect, entry.taskName]);
    const effectiveDuration = entry.endMs != null
        ? entry.endMs - entry.startMs
        : nowMs - entry.startMs;
    return (_jsxs("button", { type: "button", onClick: handleClick, className: cn("flex w-full items-center gap-2 px-2 py-0.5 text-left transition-colors hover:bg-[var(--stgm-muted,#f5f5f5)]", isSelected && "bg-[var(--stgm-accent,#f0f4ff)]", className), "aria-label": `Task ${entry.taskName}, ${entry.status}, ${formatDuration(entry.durationMs || effectiveDuration)}`, "data-task-name": entry.taskName, children: [_jsxs("div", { className: "flex w-36 shrink-0 items-center gap-1.5 overflow-hidden", children: [_jsx(StatusDot, { status: entry.status }), _jsx("span", { className: "truncate text-[11px] font-medium text-[var(--stgm-foreground,#171717)]", children: entry.taskName })] }), _jsx("span", { className: "w-14 shrink-0 text-right text-[10px] tabular-nums text-[var(--stgm-muted-foreground,#737373)]", children: entry.status === "skipped" || entry.status === "not_reached"
                    ? "—"
                    : formatDuration(entry.durationMs || effectiveDuration) }), _jsx("span", { className: "w-12 shrink-0 text-right text-[10px] tabular-nums text-[var(--stgm-muted-foreground,#737373)]", children: entry.costMicros > BIGINT_ZERO
                    ? formatMicroUsd(entry.costMicros)
                    : "" }), _jsx("div", { className: "min-w-0 flex-1", children: _jsx(WaterfallBar, { entry: entry, totalMs: totalMs, nowMs: nowMs }) })] }));
});
// ---------------------------------------------------------------------------
// Status dot
// ---------------------------------------------------------------------------
function StatusDot({ status }) {
    const color = STATUS_DOT_COLORS[status] ?? "bg-[var(--stgm-muted,#d4d4d4)]";
    return (_jsx("span", { className: cn("inline-block size-1.5 shrink-0 rounded-full", color), "aria-hidden": "true" }));
}
const STATUS_DOT_COLORS = {
    completed: "bg-[var(--stgm-success,#22c55e)]",
    running: "bg-[var(--stgm-primary,#3b82f6)]",
    failed: "bg-[var(--stgm-destructive,#ef4444)]",
    retrying: "bg-[var(--stgm-warning,#f59e0b)]",
    waiting_approval: "bg-[var(--stgm-warning,#f59e0b)]",
    skipped: "bg-[var(--stgm-muted,#d4d4d4)]",
    pending: "bg-[var(--stgm-muted,#d4d4d4)]",
    not_reached: "bg-[var(--stgm-muted,#d4d4d4)]",
};
//# sourceMappingURL=WaterfallRow.js.map