"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo } from "react";
import { cn } from "@stigmer/theme";
function timeAgo(date) {
    const seconds = Math.floor((Date.now() - date.getTime()) / 1000);
    if (seconds < 60)
        return "just now";
    const minutes = Math.floor(seconds / 60);
    if (minutes < 60)
        return `${minutes}m ago`;
    const hours = Math.floor(minutes / 60);
    if (hours < 24)
        return `${hours}h ago`;
    const days = Math.floor(hours / 24);
    return `${days}d ago`;
}
/**
 * Widget showing recent failed executions from both agent and workflow
 * domains, interleaved by timestamp.
 *
 * Each row includes a type badge (Agent / Workflow), the execution name,
 * a truncated error, and a relative timestamp.
 *
 * @since Unified Platform Dashboard
 */
export const DashboardFailedRuns = memo(function DashboardFailedRuns({ failedRuns, isLoading, onViewClick, className, }) {
    if (isLoading) {
        return (_jsxs("div", { className: cn("rounded-lg border border-border bg-card p-4", className), "aria-busy": "true", children: [_jsx("div", { className: "mb-3 h-4 w-32 animate-pulse rounded bg-muted" }), _jsx("div", { className: "space-y-2", children: Array.from({ length: 3 }, (_, i) => (_jsx("div", { className: "h-10 animate-pulse rounded bg-muted/50" }, i))) })] }));
    }
    return (_jsxs("div", { className: cn("rounded-lg border border-border bg-card p-4", className), children: [_jsx("h3", { className: "mb-3 text-sm font-semibold text-foreground", children: "Recent Failures" }), failedRuns.length === 0 ? (_jsx("p", { className: "py-6 text-center text-xs text-muted-foreground", children: "No recent failures" })) : (_jsx("ul", { className: "space-y-1.5", role: "list", children: failedRuns.map((run) => (_jsxs("li", { className: "flex items-start gap-2 rounded-md px-2 py-1.5 text-xs hover:bg-muted/50", children: [_jsx("span", { className: cn("mt-0.5 shrink-0 rounded px-1 py-0.5 text-[10px] font-medium leading-none", run.type === "agent_execution"
                                ? "bg-primary/10 text-primary"
                                : "bg-muted text-muted-foreground"), children: run.type === "agent_execution" ? "Agent" : "Workflow" }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("p", { className: "truncate font-medium text-foreground", children: run.name }), run.error && (_jsx("p", { className: "truncate text-muted-foreground", children: run.error }))] }), _jsx("span", { className: "shrink-0 text-muted-foreground", children: timeAgo(run.failedAt) }), onViewClick && (_jsx("button", { type: "button", onClick: () => onViewClick(run.id, run.type), className: "shrink-0 text-primary hover:underline", children: "View" }))] }, run.id))) }))] }));
});
//# sourceMappingURL=DashboardFailedRuns.js.map