"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that deletes an AgentInstance resource.
 *
 * Wraps `stigmer.agentInstance.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).
 *
 * Unlike WorkflowInstance, deletion does **not** cascade to runtime
 * resources: sessions previously started against the instance and
 * their execution history remain intact. The confirmation UI copy
 * should reflect this.
 *
 * @example
 * ```tsx
 * const { deleteInstance, isDeleting } = useDeleteAgentInstance();
 *
 * const handleDelete = async () => {
 *   await deleteInstance(instance.metadata.id);
 *   refetch(); // refresh list after deletion
 * };
 * ```
 */
export function useDeleteAgentInstance() {
    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.agentInstance.delete(id);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsDeleting(false);
        }
    }, [stigmer]);
    return { deleteInstance, isDeleting, error, clearError };
}
//# sourceMappingURL=useDeleteAgentInstance.js.map