"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks.js";
import { toError } from "../internal/toError.js";
/**
 * Mutation hook that updates an existing Workflow resource.
 *
 * Wraps `stigmer.workflow.update(input)` with loading and error state.
 * The caller must provide a **complete** `WorkflowInput` -- the backend
 * performs full spec replacement. Use `workflowToInput()` to reconstruct
 * the input from a fetched workflow, modify the desired field, and pass
 * the result here.
 */
export function useUpdateWorkflow() {
    const stigmer = useStigmer();
    const [isUpdating, setIsUpdating] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const update = useCallback(async (input) => {
        setIsUpdating(true);
        setError(null);
        try {
            return await stigmer.workflow.update(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsUpdating(false);
        }
    }, [stigmer]);
    return { update, isUpdating, error, clearError };
}
//# sourceMappingURL=useUpdateWorkflow.js.map