"use client";
import { create } from "@bufbuild/protobuf";
import { GetEventLogRequestSchema } from "@stigmer/protos/ai/stigmer/agentic/workflowexecution/v1/io_pb";
import { useStigmer } from "../hooks.js";
import { useFetch } from "../internal/useFetch.js";
const INITIAL_DATA = {
    events: [],
    hasMore: false,
    latestSequence: BigInt(0),
};
/**
 * Data hook that fetches the paginated event log for a workflow execution.
 *
 * Pass `null` for `executionId` to skip fetching. Supports cursor-based
 * pagination via `afterSequence` and optional filters by event type or
 * task name.
 *
 * @example
 * ```tsx
 * const { events, hasMore, latestSequence } = useWorkflowExecutionEventLog(
 *   executionId,
 *   { pageSize: 50 },
 * );
 * ```
 */
export function useWorkflowExecutionEventLog(executionId, options) {
    const stigmer = useStigmer();
    const pageSize = options?.pageSize ?? 100;
    const afterSequence = options?.afterSequence ?? BigInt(0);
    const eventTypes = options?.eventTypes ?? [];
    const taskName = options?.taskName ?? "";
    const fetchFn = executionId
        ? async () => {
            const resp = await stigmer.workflowExecution.getEventLog(create(GetEventLogRequestSchema, {
                executionId,
                afterSequence,
                eventTypes: [...eventTypes],
                taskName,
                pageSize,
            }));
            return {
                events: [...resp.events],
                hasMore: resp.hasMore,
                latestSequence: resp.latestSequence,
            };
        }
        : null;
    const { data, isLoading, isRefetching, error, refetch } = useFetch(fetchFn, [executionId, stigmer, pageSize, afterSequence, taskName, ...eventTypes], INITIAL_DATA);
    return {
        events: data.events,
        hasMore: data.hasMore,
        latestSequence: data.latestSequence,
        isLoading,
        isRefetching,
        error,
        refetch,
    };
}
//# sourceMappingURL=useWorkflowExecutionEventLog.js.map