"use client";
import { useCallback, useState } from "react";
import { create } from "@bufbuild/protobuf";
import { UpdateExecutionVisibilityInputSchema } from "@stigmer/protos/ai/stigmer/agentic/workflowinstance/v1/io_pb";
import { useStigmer } from "../../hooks.js";
import { toError } from "../../internal/toError.js";
/**
 * Mutation hook that updates the execution (run) visibility of a
 * WorkflowInstance.
 *
 * Wraps `stigmer.workflowInstance.updateExecutionVisibility()` with
 * loading/error state. The caller is responsible for refreshing the instance
 * after a successful update.
 */
export function useUpdateWorkflowInstanceExecutionVisibility() {
    const stigmer = useStigmer();
    const [isUpdating, setIsUpdating] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const updateExecutionVisibility = useCallback(async (resourceId, executionVisibility) => {
        setIsUpdating(true);
        setError(null);
        try {
            return await stigmer.workflowInstance.updateExecutionVisibility(create(UpdateExecutionVisibilityInputSchema, {
                resourceId,
                executionVisibility,
            }));
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsUpdating(false);
        }
    }, [stigmer]);
    return { updateExecutionVisibility, isUpdating, error, clearError };
}
//# sourceMappingURL=useUpdateWorkflowInstanceExecutionVisibility.js.map