'use client'
import { useMemo } from 'react';
import '@dynamic-labs-sdk/client/core';
import '@dynamic-labs/sdk-api-core';
import '../../../client/client.js';
import '@dynamic-labs-sdk/client';
import '../../../config/ApiEndpoint.js';
import '@dynamic-labs/iconic';
import '@dynamic-labs/wallet-connector-core';
import 'react/jsx-runtime';
import '../../../context/ViewContext/ViewContext.js';
import '../../../shared/logger.js';
import '@dynamic-labs/wallet-book';
import '@dynamic-labs/utils';
import '../../constants/colors.js';
import '../../constants/values.js';
import '../../../shared/consts/index.js';
import '../../../../../_virtual/_tslib.js';
import '@dynamic-labs/multi-wallet';
import 'react-international-phone';
import '../../../store/state/nonce/nonce.js';
import { isTurnkeyEnabled } from '../../functions/isTurnkeyEnabled/isTurnkeyEnabled.js';
import '@dynamic-labs/locale';
import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../../store/state/primaryWalletId/primaryWalletId.js';
import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import { usingV3Wallets } from '../../functions/usingV3Wallets/usingV3Wallets.js';
import '../../../events/dynamicEvents.js';
import { useOnboardingCompleteUserProfile } from '../../../client/extension/user/useOnboardingCompleteUser/useOnboardingCompleteUser.js';
import { getProjectSettings } from '../../../client/extension/projectSettings/getProjectSettings/getProjectSettings.js';
import { useAuthMode } from '../../../store/state/authMode/authMode.js';

const useIsLoadingEmbeddedWallet = () => {
    const user = useOnboardingCompleteUserProfile();
    const authMode = useAuthMode();
    const projectSettings = getProjectSettings();
    // we only want to show the loading state if the user has no wallets at all, and is creating a waas wallet
    // for example if they sign up with phantom wallet, we don't want to show the loading state
    // always return false for connect-only mode, because verified credentials are not used in this mode
    // except when user is logging in with email and will get an embedded wallet
    const isLoadingEmbeddedWallet = useMemo(() => {
        var _a, _b;
        if (!usingV3Wallets(projectSettings) ||
            !isTurnkeyEnabled(projectSettings)) {
            return false;
        }
        const isEmailLogin = (_a = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _a === void 0 ? void 0 : _a.some((credential) => credential.format === 'email');
        const hasWallet = (_b = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _b === void 0 ? void 0 : _b.some((credential) => credential.format === 'blockchain');
        if (authMode === 'connect-only') {
            if (isEmailLogin) {
                if (hasWallet) {
                    return false;
                }
                return true;
            }
            // login with injected wallet will already have a primary wallet set so we dont need to show loading state
            return false;
        }
        // If user has NO blockchain credential, then we show loading state
        return !hasWallet;
    }, [projectSettings, user, authMode]);
    return { isLoadingEmbeddedWallet };
};

export { useIsLoadingEmbeddedWallet };
