'use client'
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var browserWalletClient = require('@dynamic-labs-wallet/browser-wallet-client');
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
require('@dynamic-labs-sdk/client/core');
require('react');
require('eventemitter3');
require('@dynamic-labs/utils');
require('@dynamic-labs-sdk/client');
require('../../../config/ApiEndpoint.cjs');
require('@dynamic-labs/iconic');
require('react/jsx-runtime');
require('../../../context/ViewContext/ViewContext.cjs');
require('../../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('../../constants/colors.cjs');
require('../../constants/values.cjs');
require('../../../shared/consts/index.cjs');
require('../../../../../_virtual/_tslib.cjs');
require('@dynamic-labs/multi-wallet');
require('react-international-phone');
require('../../../store/state/nonce/nonce.cjs');
var apiUrl = require('../../constants/waas/apiUrl.cjs');
require('@dynamic-labs/locale');
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
require('../getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');
require('../../../events/dynamicEvents.cjs');
var isCookieEnabled = require('../../../client/extension/functions/isCookieEnabled/isCookieEnabled.cjs');

/**
 * 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) === sdkApiCore.EmbeddedWalletVersionEnum.V3;
        if (!dynamicWaasIsEnabled ||
            !(embeddedWallets === null || embeddedWallets === void 0 ? void 0 : embeddedWallets.automaticEmbeddedWalletCreation)) {
            return;
        }
        browserWalletClient.preconnectWaasIframe({
            authMode: isCookieEnabled.isCookieEnabled() ? browserWalletClient.AuthMode.COOKIE : browserWalletClient.AuthMode.HEADER,
            baseApiUrl: (apiBaseUrl || apiUrl.DEFAULT_WAAS_API_URL).replace('/api/v0', ''),
        });
    }
    catch (error) {
        // Best-effort: never break the auth flow.
        walletConnectorCore.logger.debug('preconnectDynamicWaasIframe failed', error);
    }
};

exports.preconnectDynamicWaasIframe = preconnectDynamicWaasIframe;
