'use client'
import { preconnectWaasIframe, AuthMode } from '@dynamic-labs-wallet/browser-wallet-client';
import { EmbeddedWalletVersionEnum } from '@dynamic-labs/sdk-api-core';
import { logger } from '@dynamic-labs/wallet-connector-core';
import '@dynamic-labs-sdk/client/core';
import 'react';
import 'eventemitter3';
import '@dynamic-labs/utils';
import '@dynamic-labs-sdk/client';
import '../../../config/ApiEndpoint.js';
import '@dynamic-labs/iconic';
import 'react/jsx-runtime';
import '../../../context/ViewContext/ViewContext.js';
import '../../../shared/logger.js';
import '@dynamic-labs/wallet-book';
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 { DEFAULT_WAAS_API_URL } from '../../constants/waas/apiUrl.js';
import '@dynamic-labs/locale';
import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../../store/state/primaryWalletId/primaryWalletId.js';
import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import '../getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
import '../../../events/dynamicEvents.js';
import { isCookieEnabled } from '../../../client/extension/functions/isCookieEnabled/isCookieEnabled.js';

/**
 * Warm the connection (DNS + TCP + TLS) to the WaaS iframe origin when an auth
 * flow starts, so the iframe mounted right after login loads on a hot
 * connection. Safe to call at every auth step — the SDK re-warms each call.
 *
 * Gated to v3 environments with automatic embedded-wallet creation enabled —
 * the only case where an iframe actually mounts right after sign-in.
 */
const preconnectDynamicWaasIframe = ({ apiBaseUrl, projectSettings, }) => {
    try {
        const embeddedWallets = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets;
        const dynamicWaasIsEnabled = (embeddedWallets === null || embeddedWallets === void 0 ? void 0 : embeddedWallets.defaultWalletVersion) === EmbeddedWalletVersionEnum.V3;
        if (!dynamicWaasIsEnabled ||
            !(embeddedWallets === null || embeddedWallets === void 0 ? void 0 : embeddedWallets.automaticEmbeddedWalletCreation)) {
            return;
        }
        preconnectWaasIframe({
            authMode: isCookieEnabled() ? AuthMode.COOKIE : AuthMode.HEADER,
            baseApiUrl: (apiBaseUrl || DEFAULT_WAAS_API_URL).replace('/api/v0', ''),
        });
    }
    catch (error) {
        // Best-effort: never break the auth flow.
        logger.debug('preconnectDynamicWaasIframe failed', error);
    }
};

export { preconnectDynamicWaasIframe };
