"use client";
import { create } from "@bufbuild/protobuf";
import { GetExecutionSummaryRequestSchema, SummaryTimeWindow, } from "@stigmer/protos/ai/stigmer/agentic/workflowexecution/v1/io_pb";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
/**
 * Data hook that fetches aggregated execution statistics for an organization,
 * optionally scoped to a single workflow.
 *
 * Returns phase counts, cost totals, average duration, top failing workflows,
 * and per-workflow cost breakdowns — scoped to a configurable time window.
 *
 * @example
 * ```tsx
 * // Org-level dashboard summary
 * const { summary } = useWorkflowDashboardSummary({ org: "acme" });
 *
 * // Per-workflow overview summary
 * const { summary } = useWorkflowDashboardSummary({
 *   org: "acme",
 *   workflowId: "wf-abc123",
 * });
 * ```
 */
export function useWorkflowDashboardSummary(options) {
    const stigmer = useStigmer();
    const org = options.org ?? "";
    const timeWindow = options.timeWindow ?? SummaryTimeWindow.LAST_7D;
    const workflowId = options.workflowId ?? "";
    const refetchInterval = options.refetchInterval ?? 0;
    const fetchFn = org
        ? async () => {
            const req = { org, timeWindow };
            if (workflowId)
                req.workflowId = workflowId;
            return await stigmer.workflowExecution.getExecutionSummary(create(GetExecutionSummaryRequestSchema, req));
        }
        : null;
    const { data, isLoading, isRefetching, error, refetch } = useFetch(fetchFn, [stigmer, org, timeWindow, workflowId], null, { refetchInterval: refetchInterval || false });
    return { summary: data, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useWorkflowDashboardSummary.js.map