"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that wraps `identityProvider.delete()` with loading
 * and error state.
 *
 * Deletes an identity provider by its resource ID. Returns the deleted
 * {@link IdentityProvider} on success so callers can confirm which
 * provider was removed.
 *
 * Deletion is blocked by the backend if any platform-managed
 * organizations still reference this identity provider.
 *
 * @example
 * ```tsx
 * const { deleteProvider, isDeleting, error } = useDeleteIdentityProvider();
 *
 * await deleteProvider({ resourceId: "idp-abc123" });
 * refetch(); // refresh the list after deletion
 * ```
 */
export function useDeleteIdentityProvider() {
    const stigmer = useStigmer();
    const [isDeleting, setIsDeleting] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const deleteProvider = useCallback(async (input) => {
        setIsDeleting(true);
        setError(null);
        try {
            return await stigmer.identityProvider.delete(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsDeleting(false);
        }
    }, [stigmer]);
    return { deleteProvider, isDeleting, error, clearError };
}
//# sourceMappingURL=useDeleteIdentityProvider.js.map