'use client'
// JWT scope strings, kept as string literals rather than the JwtScope enum on
// purpose: this module is re-exported from the widely-imported shared
// `functions` barrel, and reading a JwtScope enum member at module-load time
// crashes every importing test suite when the enum has not initialized yet
// (circular-import load order). Mirrors hasPendingMfaAction, which checks the
// same scope string directly.
const USER_BASIC_SCOPE = 'user:basic';
// Scopes that mean login is not yet fully complete (MFA / KYC / device
// registration still pending), i.e. the JWT has not upgraded to user:basic.
const PRE_BASIC_RESTRICTED_SCOPES = [
    'requiresAdditionalAuth',
    'userDataForm',
    'device:register',
];
/**
 * Returns true only when the user's JWT has fully upgraded to `user:basic`
 * with no pending scope.
 *
 * WaaS wallet creation (`createRooms`) is rejected by the backend with a 401
 * for any non-`user:basic` token, so callers must wait for this before
 * triggering creation. Gating on the user object's requirement flags alone is
 * not enough: those flags can clear before the upgraded token lands, racing the
 * token and firing `createRooms` with a still-pending scope.
 */
// Only the JWT `scope` is needed, so accept any user-shaped object that carries
// it. This keeps the predicate decoupled from the user type (and avoids the
// deprecated UserProfile type) while accepting both UserProfile and SdkUser.
const hasUserBasicScope = (user) => {
    var _a, _b;
    const scopes = (_b = (_a = user === null || user === void 0 ? void 0 : user.scope) === null || _a === void 0 ? void 0 : _a.split(' ')) !== null && _b !== void 0 ? _b : [];
    return (scopes.includes(USER_BASIC_SCOPE) &&
        !scopes.some((scope) => PRE_BASIC_RESTRICTED_SCOPES.includes(scope)));
};

export { hasUserBasicScope };
