"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { memo, useCallback, useMemo, useState } from "react";
import { cn } from "@stigmer/theme";
import { useWorkflowDashboardSummary } from "../useWorkflowDashboardSummary";
import { useWorkflowExecutionList } from "../useWorkflowExecutionList";
import { deriveExecutionRows, filterExecutionRows } from "./derive-execution-row";
import { ExecutionHistoryTable } from "./ExecutionHistoryTable";
import { ExecutionFilterBar } from "./ExecutionFilterBar";
import { HealthMetricsStrip } from "./HealthMetricsStrip";
import { FailureAnalysisPanel } from "./FailureAnalysisPanel";
/**
 * Composed execution history view assembling health metrics, a filter
 * bar, a sortable data table, and a failure analysis panel.
 *
 * Self-contained: fetches data internally via `useWorkflowExecutionList`
 * and `useWorkflowDashboardSummary`. Zero Console dependencies.
 *
 * Layout:
 * ```
 * HealthMetricsStrip
 * ExecutionFilterBar
 * ExecutionHistoryTable
 * FailureAnalysisPanel (collapsible)
 * ```
 *
 * @example
 * ```tsx
 * <WorkflowExecutionHistory
 *   org="acme"
 *   workflowId={workflow.metadata?.id}
 *   onExecutionClick={(id) => navigate(`/executions/${id}`)}
 * />
 * ```
 */
export const WorkflowExecutionHistory = memo(function WorkflowExecutionHistory({ org, workflowId, onExecutionClick, pageSize = 20, className, }) {
    const [clientFilters, setClientFilters] = useState({});
    const { summary, isLoading: summaryLoading } = useWorkflowDashboardSummary({
        org,
        workflowId,
        refetchInterval: 60_000,
    });
    const { executions, isLoading: listLoading, error: listError, } = useWorkflowExecutionList({ workflowId, pageSize });
    const allRows = useMemo(() => deriveExecutionRows(executions), [executions]);
    const filteredRows = useMemo(() => {
        if (Object.keys(clientFilters).length === 0)
            return allRows;
        return filterExecutionRows(allRows, clientFilters);
    }, [allRows, clientFilters]);
    const handleFiltersChange = useCallback((next) => {
        setClientFilters(next);
    }, []);
    return (_jsxs("section", { "aria-label": "Execution history", className: cn("flex flex-col gap-4", className), children: [_jsx(HealthMetricsStrip, { summary: summary, isLoading: summaryLoading }), _jsx(ExecutionFilterBar, { filters: clientFilters, onFiltersChange: handleFiltersChange }), _jsx(ExecutionHistoryTable, { rows: filteredRows, isLoading: listLoading, error: listError, onRowClick: onExecutionClick }), _jsx(FailureAnalysisPanel, { executions: executions, onExecutionClick: onExecutionClick })] }));
});
//# sourceMappingURL=WorkflowExecutionHistory.js.map