"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that wraps `runner.delete()` with loading and error
 * state.
 *
 * Deletes a runner by its resource ID. Returns the deleted
 * {@link Runner} on success so callers can confirm which runner was
 * removed (e.g., in a toast or undo prompt).
 *
 * @example
 * ```tsx
 * const { deleteRunner, isDeleting, error } = useDeleteRunner();
 *
 * await deleteRunner("rnr_abc123");
 * refetch(); // refresh the runner list
 * ```
 */
export function useDeleteRunner() {
    const stigmer = useStigmer();
    const [isDeleting, setIsDeleting] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const deleteRunner = useCallback(async (id) => {
        setIsDeleting(true);
        setError(null);
        try {
            return await stigmer.runner.delete(id);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsDeleting(false);
        }
    }, [stigmer]);
    return { deleteRunner, isDeleting, error, clearError };
}
//# sourceMappingURL=useDeleteRunner.js.map