'use client'
import { jsx } from 'react/jsx-runtime';
import { DynamicBaseWidget } from '../../components/DynamicBaseWidget/DynamicBaseWidget.js';
import { useMultiWalletPromptState } from '../DynamicWidget/hooks/useMultiWalletPromptState/useMultiWalletPromptState.js';
import { DetectedNewWalletModal } from '../DynamicWidget/prompts/DetectedNewWalletModal/DetectedNewWalletModal.js';
import { PendingAccountSwitchToLinkModal } from '../DynamicWidget/prompts/PendingAccountSwitchToLinkModal/PendingAccountSwitchToLinkModal.js';
import { PendingAccountSwitchModal } from '../DynamicWidget/prompts/PendingAccountSwitchModal/PendingAccountSwitchModal.js';
import { AwaitingConnectionModal } from '../DynamicWidget/prompts/AwaitingConnectionModal/AwaitingConnectionModal.js';
import { PendingSignModal } from '../DynamicWidget/prompts/PendingSignModal/PendingSignModal.js';
import { PrimaryNotConnectedModal } from '../DynamicWidget/prompts/PrimaryNotConnectedModal/PrimaryNotConnectedModal.js';
import { UnlinkWalletPopUpModal } from '../DynamicWidget/prompts/UnlinkWalletPopUp/UnlinkWalletPopUp.js';
import 'react';
import '../../events/dynamicEvents.js';
import '../../../../_virtual/_tslib.js';
import '@dynamic-labs/utils';
import '../../context/DynamicContext/useDynamicContext/useDynamicContext.js';
import { useInternalDynamicContext } from '../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
import '@dynamic-labs/wallet-connector-core';
import '../../context/CaptchaContext/CaptchaContext.js';
import '@dynamic-labs/sdk-api-core';
import '../../context/ErrorContext/ErrorContext.js';
import '../../context/ViewContext/ViewContext.js';
import '@dynamic-labs/iconic';
import { logger } from '../../shared/logger.js';
import '@dynamic-labs/wallet-book';
import '../../utils/constants/colors.js';
import '../../utils/constants/values.js';
import '../../shared/consts/index.js';
import '@dynamic-labs/multi-wallet';
import 'react-international-phone';
import '../../store/state/nonce/nonce.js';
import '@dynamic-labs-wallet/browser-wallet-client';
import '@dynamic-labs-sdk/client/core';
import 'eventemitter3';
import '@dynamic-labs-sdk/client';
import '../../config/ApiEndpoint.js';
import '@dynamic-labs/locale';
import '../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../store/state/primaryWalletId/primaryWalletId.js';
import '../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import '../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
import '../../context/AccessDeniedContext/AccessDeniedContext.js';
import '../../context/AccountExistsContext/AccountExistsContext.js';
import '../../context/UserWalletsContext/UserWalletsContext.js';
import '../../store/state/authMode/authMode.js';
import '../../store/state/loadingAndLifecycle/loadingAndLifecycle.js';
import '../../context/VerificationContext/VerificationContext.js';
import 'react-dom';
import '../../utils/functions/compareChains/compareChains.js';
import '../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.js';
import '../../context/ThemeContext/ThemeContext.js';
import { useIsLoggedIn } from '../../utils/hooks/useIsLoggedIn/useIsLoggedIn.js';
import '../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.js';
import 'bs58';
import '@dynamic-labs/types';
import '../../context/SocialRedirectContext/SocialRedirectContext.js';
import '../../context/LoadingContext/LoadingContext.js';
import '../../context/WalletContext/WalletContext.js';
import '../../utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.js';
import 'yup';
import '../../context/MockContext/MockContext.js';
import '../../views/CollectUserDataView/useFields.js';
import '../../context/FieldsStateContext/FieldsStateContext.js';
import '../../context/UserFieldEditorContext/UserFieldEditorContext.js';
import '@dynamic-labs/rpc-providers';
import '../../store/state/walletOptions/walletOptions.js';
import 'react-i18next';
import '../../components/Accordion/components/AccordionItem/AccordionItem.js';
import '../../components/Alert/Alert.js';
import '../../components/ShadowDOM/ShadowDOM.js';
import '../../components/IconButton/IconButton.js';
import '../../components/InlineWidget/InlineWidget.js';
import '../../components/Input/Input.js';
import '../../components/IsBrowser/IsBrowser.js';
import '../../components/MenuList/Dropdown/Dropdown.js';
import '../../components/OverlayCard/OverlayCard.js';
import '../../components/Transition/ZoomTransition/ZoomTransition.js';
import '../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
import '../../components/Transition/OpacityTransition/OpacityTransition.js';
import '../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
import '../../components/Popper/Popper/Popper.js';
import '../../components/Popper/PopperContext/PopperContext.js';
import 'react-focus-lock';
import 'qrcode';
import 'formik';
import '../../utils/hooks/useSubdomainCheck/useSubdomainCheck.js';
import '../../context/WalletGroupContext/WalletGroupContext.js';
import '../DynamicWidget/context/DynamicWidgetContext.js';
import '../../utils/hooks/useGetMfaToken/useGetMfaToken.js';
import '../../utils/hooks/useWalletBackup/useWalletBackup.js';
import '../../utils/hooks/useWalletBackup/BackupError.js';
import '../../utils/hooks/useWalletBackup/types.js';
import '../../utils/hooks/useWalletBackup/cloudProviders.js';
import '@hcaptcha/react-hcaptcha';
import '@marsidev/react-turnstile';
import '../../context/IpConfigurationContext/IpConfigurationContext.js';
import '../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
import '../DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
import '../DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.js';
import '../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.js';
import '../../context/ErrorContext/hooks/useErrorText/useErrorText.js';
import '../../context/FooterAnimationContext/index.js';
import '../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.js';
import '../../context/PasskeyContext/PasskeyContext.js';
import '../../context/OnrampContext/OnrampContext.js';
import '../../utils/hooks/useWalletDelegation/DelegationError.js';
import '../../store/state/sendBalances.js';
import '../../store/state/connectorsInitializing/connectorsInitializing.js';
import '../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.js';
import '../DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
import '../../views/TransactionConfirmationView/TransactionConfirmationView.js';
import '../DynamicWidget/components/PasskeyCard/PasskeyCard.js';
import '../DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.js';
import '../../../index.js';
import '../DynamicWidget/views/ManagePasskeysMfaWidgetView/ManagePasskeysMfaWidgetView.js';
import '../DynamicWidget/views/ManageTotpMfaWidgetView/ManageTotpMfaWidgetView.js';
import '../DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.js';
import '../../store/state/tokenBalances.js';
import '../../store/state/multichainBalances.js';
import '@dynamic-labs/store';
import '../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
import { useWidgetRegistryCheck } from '../../context/WidgetRegistry/WidgetRegistryContextProvider.js';

const DynamicMultiWalletPromptsWidget = () => {
    const isLoggedIn = useIsLoggedIn();
    const isUserProfilePresent = useWidgetRegistryCheck('user-profile');
    const { showAuthFlow, showDynamicUserProfile } = useInternalDynamicContext();
    const isRenderingSignMessageInLinkWalletModal = showAuthFlow || (showDynamicUserProfile && isUserProfilePresent);
    const multiWalletPromptState = useMultiWalletPromptState();
    const mapMultiWalletPromptStateToModalComponent = {
        awaiting_connection: AwaitingConnectionModal,
        detected_new_wallet: DetectedNewWalletModal,
        linking_new_wallet: PendingAccountSwitchToLinkModal,
        pending_account_switch: PendingAccountSwitchModal,
        pending_sign: PendingSignModal,
        primary_not_connected: PrimaryNotConnectedModal,
        unlink_wallet: UnlinkWalletPopUpModal,
    };
    logger.logVerboseTroubleshootingMessage('[DynamicMultiWalletPromptsWidget]', {
        isLoggedIn,
        isRenderingSignMessageInLinkWalletModal,
        multiWalletPromptState,
    });
    if (multiWalletPromptState === 'idle' ||
        isRenderingSignMessageInLinkWalletModal ||
        !isLoggedIn)
        return null;
    const ModalComponent = mapMultiWalletPromptStateToModalComponent[multiWalletPromptState];
    return (jsx(DynamicBaseWidget, { children: jsx(ModalComponent, {}) }));
};

export { DynamicMultiWalletPromptsWidget };
