"use client";
import { create } from "@bufbuild/protobuf";
import { GetWorkflowInstancesByWorkflowRequestSchema } from "@stigmer/protos/ai/stigmer/agentic/workflowinstance/v1/io_pb";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
/**
 * Data hook that fetches all instances for a specific workflow.
 *
 * Wraps `stigmer.workflowInstance.getByWorkflow()` with loading
 * and error state management. Used on the Workflow detail page
 * "Instances" tab to show environment-bound deployments.
 *
 * Pass `null` as `workflowId` to skip fetching (stable no-op).
 *
 * @example
 * ```tsx
 * const { instances, isLoading } = useWorkflowInstances(workflow.metadata?.id);
 * ```
 */
export function useWorkflowInstances(workflowId) {
    const stigmer = useStigmer();
    const fetchFn = workflowId
        ? async () => {
            const resp = await stigmer.workflowInstance.getByWorkflow(create(GetWorkflowInstancesByWorkflowRequestSchema, {
                workflowId,
            }));
            return resp.entries ? [...resp.entries] : [];
        }
        : null;
    const { data: instances, isLoading, isRefetching, error, refetch, } = useFetch(fetchFn, [workflowId, stigmer], []);
    return { instances, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useWorkflowInstances.js.map