"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../../hooks";
import { toError } from "../../internal/toError";
/**
 * Mutation hook that deletes a WorkflowInstance resource.
 *
 * Wraps `stigmer.workflowInstance.delete()` with loading/error state.
 * The caller is responsible for handling post-delete UI updates
 * (e.g., refreshing the instance list, closing a detail panel).
 *
 * Deletion cascades to all WorkflowExecution resources that belong
 * to the instance. The confirmation UI should warn the user about this.
 *
 * @example
 * ```tsx
 * const { deleteInstance, isDeleting } = useDeleteWorkflowInstance();
 *
 * const handleDelete = async () => {
 *   await deleteInstance(instance.metadata.id);
 *   refetch(); // refresh list after deletion
 * };
 * ```
 */
export function useDeleteWorkflowInstance() {
    const stigmer = useStigmer();
    const [isDeleting, setIsDeleting] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const deleteInstance = useCallback(async (id) => {
        setIsDeleting(true);
        setError(null);
        try {
            return await stigmer.workflowInstance.delete(id);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsDeleting(false);
        }
    }, [stigmer]);
    return { deleteInstance, isDeleting, error, clearError };
}
//# sourceMappingURL=useDeleteWorkflowInstance.js.map