"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Behavior hook that wraps `invitation.revoke()` with loading and
 * error state.
 *
 * Revokes an active invitation by its resource ID, setting its state
 * to `revoked` and preventing further redemptions. The operation is
 * idempotent — revoking an already-revoked invitation is a no-op
 * that returns the unchanged resource.
 *
 * Returns the updated {@link Invitation} so callers can verify the
 * new state. Call `refetch()` on the list hook after revocation to
 * refresh the invitation list.
 *
 * @example
 * ```tsx
 * const { revoke, isRevoking, error } = useRevokeInvitation();
 *
 * await revoke("inv-abc123");
 * refetch(); // refresh the invitation list
 * ```
 */
export function useRevokeInvitation() {
    const stigmer = useStigmer();
    const [isRevoking, setIsRevoking] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const revoke = useCallback(async (id) => {
        setIsRevoking(true);
        setError(null);
        try {
            return await stigmer.invitation.revoke(id);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsRevoking(false);
        }
    }, [stigmer]);
    return { revoke, isRevoking, error, clearError };
}
//# sourceMappingURL=useRevokeInvitation.js.map