'use client'
'use strict';

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

var primaryWalletId = require('../../../../store/state/primaryWalletId/primaryWalletId.cjs');
require('@dynamic-labs/sdk-api-core');
require('../../../../utils/constants/values.cjs');
require('@dynamic-labs/utils');
require('../../../../../../_virtual/_tslib.cjs');
require('@dynamic-labs/multi-wallet');
require('react-international-phone');
require('../../../../utils/constants/colors.cjs');
require('@dynamic-labs/iconic');
require('@dynamic-labs/wallet-connector-core');
require('react');
require('react/jsx-runtime');
require('../../../ViewContext/ViewContext.cjs');
require('../../../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('../../../../shared/consts/index.cjs');
require('../../../../store/state/nonce/nonce.cjs');
var updatePrimaryWalletId = require('../../../../utils/functions/updatePrimaryWalletId/updatePrimaryWalletId.cjs');
require('../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
require('../../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('@dynamic-labs-sdk/client/core');
require('../../../../client/client.cjs');
require('@dynamic-labs-sdk/client');
require('../../../../config/ApiEndpoint.cjs');
require('../../../../events/dynamicEvents.cjs');
require('@dynamic-labs/locale');
var useDynamicEvents = require('../../../../utils/hooks/events/useDynamicEvents/useDynamicEvents.cjs');
require('../../DynamicContext.cjs');
require('../../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
require('../../../../store/state/authMode/authMode.cjs');
require('../../../CaptchaContext/CaptchaContext.cjs');
require('../../../ErrorContext/ErrorContext.cjs');
require('../../../AccessDeniedContext/AccessDeniedContext.cjs');
require('../../../AccountExistsContext/AccountExistsContext.cjs');
require('../../../UserWalletsContext/UserWalletsContext.cjs');
require('../../../VerificationContext/VerificationContext.cjs');
require('react-dom');
require('../../../../utils/functions/compareChains/compareChains.cjs');
require('../../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
require('../../../ThemeContext/ThemeContext.cjs');
require('../../../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
require('bs58');
require('@dynamic-labs/types');
require('../../../SocialRedirectContext/SocialRedirectContext.cjs');
require('../../../LoadingContext/LoadingContext.cjs');
require('../../../WalletContext/WalletContext.cjs');
require('../../../../utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs');
require('yup');
require('../../../MockContext/MockContext.cjs');
require('../../../../views/CollectUserDataView/useFields.cjs');
require('../../../FieldsStateContext/FieldsStateContext.cjs');
require('../../../UserFieldEditorContext/UserFieldEditorContext.cjs');
require('@dynamic-labs/rpc-providers');
require('../../../../store/state/walletOptions/walletOptions.cjs');
require('react-i18next');
require('../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
require('../../../../components/Alert/Alert.cjs');
require('../../../../components/ShadowDOM/ShadowDOM.cjs');
require('../../../../components/IconButton/IconButton.cjs');
require('../../../../components/InlineWidget/InlineWidget.cjs');
require('../../../../components/Input/Input.cjs');
require('../../../../components/IsBrowser/IsBrowser.cjs');
require('../../../../components/MenuList/Dropdown/Dropdown.cjs');
require('../../../../components/OverlayCard/OverlayCard.cjs');
require('../../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
require('../../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
require('../../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
require('../../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
require('../../../../components/Popper/Popper/Popper.cjs');
require('../../../../components/Popper/PopperContext/PopperContext.cjs');
require('react-focus-lock');
require('qrcode');
require('formik');
require('../../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
require('../../../WalletGroupContext/WalletGroupContext.cjs');
require('../../../IpConfigurationContext/IpConfigurationContext.cjs');
require('../../../ConnectWithOtpContext/ConnectWithOtpContext.cjs');
require('../../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
require('@hcaptcha/react-hcaptcha');
require('../../../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
require('../../../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.cjs');
require('../../../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.cjs');
require('../../../ErrorContext/hooks/useErrorText/useErrorText.cjs');
require('../../../FooterAnimationContext/index.cjs');
require('../../../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.cjs');
require('../../../PasskeyContext/PasskeyContext.cjs');
require('../../../OnrampContext/OnrampContext.cjs');
require('../../../../store/state/sendBalances.cjs');
require('../../../../store/state/connectorsInitializing/connectorsInitializing.cjs');
require('../../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
require('../../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
require('../../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
require('../../../../widgets/DynamicWidget/components/PasskeyCard/PasskeyCard.cjs');
require('../../../../widgets/DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.cjs');
require('../../../../../index.cjs');
require('../../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
require('../../../../store/state/tokenBalances.cjs');
require('../../../../store/state/multichainBalances.cjs');
require('../../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');

/* eslint-disable prefer-destructuring */
/**
 * Whenever user wallets are populated, this hook will automatically select a wallet as the primary wallet.
 *
 * This logic doesn't apply when embedded wallets are enabled though, as the primary wallet will be selected
 * as the embedded wallet.
 */
const useAutoselectPrimaryWallet = (isBridgeFlow) => {
    useDynamicEvents.useInternalDynamicEvents('userWalletsPopulated', (userWallets) => {
        if (isBridgeFlow ||
            userWallets.some((wallet) => wallet.connector.isEmbeddedWallet))
            return;
        if (primaryWalletId.getPrimaryWalletId())
            return;
        const firstWallet = userWallets[0];
        if (!firstWallet)
            return;
        updatePrimaryWalletId.updatePrimaryWalletId(firstWallet.id);
    });
};

exports.useAutoselectPrimaryWallet = useAutoselectPrimaryWallet;
