"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Behavior hook that wraps `iamPolicy.delete()` with loading/error
 * state.
 *
 * Removes an IAM policy binding — revoking a principal's role on a
 * resource. The caller provides the same {@link IamPolicySpec} that was
 * used when creating the binding.
 *
 * @example
 * ```tsx
 * const { remove, isDeleting, error } = useDeleteIamPolicy();
 *
 * await remove({
 *   principal: { kind: "identity_account", id: accountId },
 *   resource: { kind: "organization", id: orgId },
 *   relation: "admin",
 * });
 * ```
 */
export function useDeleteIamPolicy() {
    const stigmer = useStigmer();
    const [isDeleting, setIsDeleting] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const remove = useCallback(async (spec) => {
        setIsDeleting(true);
        setError(null);
        try {
            return await stigmer.iamPolicy.delete(spec);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsDeleting(false);
        }
    }, [stigmer]);
    return { remove, isDeleting, error, clearError };
}
//# sourceMappingURL=useDeleteIamPolicy.js.map