"use client";
import { useMemo } from "react";
import { useWorkflowExecutionList } from "../useWorkflowExecutionList";
import { deriveExecutionRows, filterExecutionRows, } from "./derive-execution-row";
/**
 * Behavior hook that composes {@link useWorkflowExecutionList} with the
 * {@link deriveExecutionRows} derivation pipeline and optional client-side
 * filters.
 *
 * Returns pre-computed {@link ExecutionRow} objects ready for rendering
 * by {@link ExecutionHistoryTable}.
 *
 * @example
 * ```tsx
 * const { rows, isLoading, error, refetch } = useExecutionHistoryData({
 *   workflowId: "wf_onboarding",
 *   pageSize: 20,
 *   clientFilters: { phases: [ExecutionPhase.EXECUTION_FAILED] },
 * });
 * ```
 */
export function useExecutionHistoryData(options) {
    const workflowId = options?.workflowId ?? null;
    const pageSize = options?.pageSize ?? 20;
    const pageToken = options?.pageToken;
    const clientFilters = options?.clientFilters;
    const { executions, totalPages, isLoading, isRefetching, error, refetch, } = useWorkflowExecutionList({ workflowId, pageSize, pageToken });
    const derivedRows = useMemo(() => deriveExecutionRows(executions), [executions]);
    const filteredRows = useMemo(() => {
        if (!clientFilters || Object.keys(clientFilters).length === 0) {
            return derivedRows;
        }
        return filterExecutionRows(derivedRows, clientFilters);
    }, [derivedRows, clientFilters]);
    return useMemo(() => ({
        rows: filteredRows,
        totalPages,
        isLoading,
        isRefetching,
        error,
        refetch,
    }), [filteredRows, totalPages, isLoading, isRefetching, error, refetch]);
}
//# sourceMappingURL=useExecutionHistoryData.js.map