"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that wraps `oauthapp.delete()` with loading and error
 * state.
 *
 * Deletes an OAuth app by its resource ID. Returns the deleted
 * {@link OAuthApp} on success so callers can confirm which app was
 * removed. The deletion is permanent — any MCP server overrides
 * referencing this app will lose their binding.
 *
 * @example
 * ```tsx
 * const { deleteApp, isDeleting, error } = useDeleteOAuthApp();
 *
 * await deleteApp("oauth-app-id-abc123");
 * refetch(); // refresh the list after deletion
 * ```
 */
export function useDeleteOAuthApp() {
    const stigmer = useStigmer();
    const [isDeleting, setIsDeleting] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const deleteApp = useCallback(async (id) => {
        setIsDeleting(true);
        setError(null);
        try {
            return await stigmer.oauthapp.delete({ resourceId: id });
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsDeleting(false);
        }
    }, [stigmer]);
    return { deleteApp, isDeleting, error, clearError };
}
//# sourceMappingURL=useDeleteOAuthApp.js.map