// packages/ui/src/utils/useOAuthSafe.ts
import { DEGRADED_OAUTH_API } from '@donotdev/core';
import * as oauthModule from '@donotdev/oauth';
// Check if real hook exists (will be undefined if Vite aliased to empty module)
const realUseOAuth = oauthModule?.useOAuth;
/**
 * Stub that returns degraded OAuth values.
 * Used when @donotdev/oauth is not installed.
 */
function useOAuthStub(key) {
    return DEGRADED_OAUTH_API[key];
}
/**
 * Safe wrapper for useOAuth hook.
 *
 * - If @donotdev/oauth installed → uses real hook (handles credentials/consent internally)
 * - If not installed → returns degraded API values
 *
 * @param key - Property name to access from OAuth API
 * @returns The OAuth API value, or degraded value if OAuth unavailable
 *
 * @example
 * ```typescript
 * const connect = useOAuthSafe('connect');
 * const loading = useOAuthSafe('loading');
 * const isAvailable = useOAuthSafe('isAvailable');
 * ```
 */
export function useOAuthSafe(key) {
    if (realUseOAuth) {
        return realUseOAuth(key);
    }
    return useOAuthStub(key);
}
/**
 * Check if OAuth module is available (for conditional UI rendering)
 */
export const isOAuthAvailable = typeof realUseOAuth === 'function';
