'use client'
'use strict';

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

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var reactI18next = require('react-i18next');
var ModalHeader = require('../../../components/ModalHeader/ModalHeader.cjs');
var Typography = require('../../../components/Typography/Typography.cjs');
var TypographyButton = require('../../../components/TypographyButton/TypographyButton.cjs');
require('../../../context/DynamicContext/DynamicContext.cjs');
require('../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
require('@dynamic-labs/iconic');
require('@dynamic-labs/wallet-connector-core');
var multipleAccountSecurity = require('../../../shared/assets/multiple-account-security.cjs');
var passkeyAccountSecurity = require('../../../shared/assets/passkey-account-security.cjs');
require('../../../context/ViewContext/ViewContext.cjs');
require('../../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('@dynamic-labs/utils');
require('../../../utils/constants/colors.cjs');
require('../../../utils/constants/values.cjs');
require('@dynamic-labs/sdk-api-core');
require('../../../shared/consts/index.cjs');
require('../../../events/dynamicEvents.cjs');
require('../../../../../_virtual/_tslib.cjs');
require('../../../context/CaptchaContext/CaptchaContext.cjs');
require('../../../context/ErrorContext/ErrorContext.cjs');
require('@dynamic-labs/multi-wallet');
require('react-international-phone');
require('../../../store/state/nonce/nonce.cjs');
var getEnabledEmbeddedWalletsAuthenticators = require('../../../utils/functions/getEnabledEmbeddedWalletsAuthenticators/getEnabledEmbeddedWalletsAuthenticators.cjs');
require('@dynamic-labs-sdk/client/core');
require('../../../client/client.cjs');
require('@dynamic-labs-sdk/client');
require('../../../config/ApiEndpoint.cjs');
require('@dynamic-labs/locale');
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
require('../../../context/AccountExistsContext/AccountExistsContext.cjs');
require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
require('../../../store/state/authMode/authMode.cjs');
require('../../../context/VerificationContext/VerificationContext.cjs');
require('react-dom');
require('../../../utils/functions/compareChains/compareChains.cjs');
require('../utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
require('../../../context/ThemeContext/ThemeContext.cjs');
var useSmartWallets = require('../../../utils/hooks/useSmartWallets/useSmartWallets.cjs');
require('../../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
var usePasskeyRecovery = require('../../../utils/hooks/usePasskeyRecovery/usePasskeyRecovery.cjs');
require('bs58');
require('@dynamic-labs/types');
require('../../../context/SocialRedirectContext/SocialRedirectContext.cjs');
require('../../../context/LoadingContext/LoadingContext.cjs');
require('../../../context/WalletContext/WalletContext.cjs');
var useIsTurnkeyWallet = require('../../../utils/hooks/useIsTurnkeyWallet/useIsTurnkeyWallet.cjs');
require('../../../utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs');
require('yup');
require('../../../context/MockContext/MockContext.cjs');
require('../../CollectUserDataView/useFields.cjs');
require('../../../context/FieldsStateContext/FieldsStateContext.cjs');
require('../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
require('@dynamic-labs/rpc-providers');
require('../../../store/state/walletOptions/walletOptions.cjs');
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');
var SupportLinks = require('../../../components/SupportLinks/SupportLinks.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('../../../context/WalletGroupContext/WalletGroupContext.cjs');
require('../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
require('../../../context/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('../../ExchangeWhitelistWarning/ExchangeWhitelistWarning.cjs');
require('../../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
require('../../../context/FooterAnimationContext/index.cjs');
require('../../MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.cjs');
require('../../../context/PasskeyContext/PasskeyContext.cjs');
var EmbeddedAuthChoiceCards = require('../EmbeddedAuthChoiceCards/EmbeddedAuthChoiceCards.cjs');
var AuthChoiceInfo = require('./AuthChoiceInfo/AuthChoiceInfo.cjs');
require('../../../context/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('../../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');
var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');

const titleDescriptionMap = {
    helpSession: {
        description: 'dyn_embedded_authenticator.need_help_description',
        title: 'dyn_embedded_authenticator.need_help_title',
    },
    reveal: {
        description: 'dyn_embedded_authenticator.reveal_description',
        title: 'dyn_embedded_authenticator.reveal_title',
    },
    sendTransaction: {
        description: 'dyn_embedded_authenticator.description',
        title: 'dyn_embedded_authenticator.title',
    },
    signMessage: {
        description: 'dyn_embedded_authenticator.description',
        title: 'dyn_embedded_authenticator.title',
    },
    signTransaction: {
        description: 'dyn_embedded_authenticator.description',
        title: 'dyn_embedded_authenticator.title',
    },
};
const EmbeddedAuthChoice = ({ currentAction, }) => {
    var _a, _b, _c;
    const { t } = reactI18next.useTranslation();
    const { primaryWallet, projectSettings, setShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
    const { getEOAWallet } = useSmartWallets.useSmartWallets();
    const wallet = (_a = (primaryWallet && getEOAWallet(primaryWallet))) !== null && _a !== void 0 ? _a : primaryWallet;
    const { initPasskeyRecoveryProcess } = usePasskeyRecovery.usePasskeyRecovery();
    const { isTurnkeyWallet } = useIsTurnkeyWallet.useIsTurnkeyWallet();
    const supportedAuthenticators = React.useMemo(() => {
        var _a;
        const supportedAuths = getEnabledEmbeddedWalletsAuthenticators.getEnabledEmbeddedWalletsAuthenticators((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.supportedSecurityMethods);
        const supportedMethods = Object.keys(supportedAuths);
        if (!currentAction ||
            !['helpSession', 'reveal'].includes(currentAction.type)) {
            return supportedMethods.filter((auth) => auth !== 'email');
        }
        return supportedMethods;
    }, [projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets]);
    const isEmailAuthSessionActive = () => {
        if (!wallet || !isTurnkeyWallet) {
            return false;
        }
        const turnkeyAuthenticatorHandler = wallet.connector.getAuthenticatorHandler();
        return turnkeyAuthenticatorHandler.isSessionActive();
    };
    const renderIcon = () => supportedAuthenticators.length > 1 ? (jsxRuntime.jsx(multipleAccountSecurity.ReactComponent, {})) : (jsxRuntime.jsx(passkeyAccountSecurity.ReactComponent, {}));
    const buttonCopyKey = isEmailAuthSessionActive()
        ? 'dyn_embedded_authenticator.passkey.auth_info.start_button'
        : 'dyn_embedded_authenticator.passkey.auth_info.add_button';
    const { title, description } = titleDescriptionMap[(currentAction === null || currentAction === void 0 ? void 0 : currentAction.type) || 'signMessage'];
    const supportUrls = (_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.general) === null || _b === void 0 ? void 0 : _b.supportUrls;
    const supportEmail = (_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.general) === null || _c === void 0 ? void 0 : _c.supportEmail;
    if (!(supportedAuthenticators === null || supportedAuthenticators === void 0 ? void 0 : supportedAuthenticators.length)) {
        return null;
    }
    return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ModalHeader.ModalHeader, { children: jsxRuntime.jsx(Typography.Typography, { as: 'h1', variant: 'title', color: 'primary', "data-testid": 'dynamic-auth-modal-heading', className: 'header__typography', copykey: title, children: t(title) }) }), jsxRuntime.jsxs("div", { className: 'embedded-auth-choice', children: [jsxRuntime.jsx("div", { className: 'embedded-auth-choice__header', children: renderIcon() }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', weight: 'regular', color: 'secondary', className: 'embedded-auth-choice__subtitle', copykey: description, children: t(description) }), supportedAuthenticators.length > 1 ? (jsxRuntime.jsx(EmbeddedAuthChoiceCards.EmbeddedAuthChoiceCards, { currentAction: currentAction, supportedAuthenticators: supportedAuthenticators })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(AuthChoiceInfo.AuthChoiceInfo, { choice: 'passkey' }), jsxRuntime.jsx(TypographyButton.TypographyButton, { dataTestId: 'passkey-only-choice-button', buttonVariant: 'brand-primary', expanded: true, onClick: () => initPasskeyRecoveryProcess('passkey'), copykey: buttonCopyKey, typographyProps: {
                                    color: 'inherit',
                                }, children: t(buttonCopyKey) })] })), (currentAction === null || currentAction === void 0 ? void 0 : currentAction.type) !== 'reveal' && (jsxRuntime.jsx(TypographyButton.TypographyButton, { buttonVariant: 'primary', buttonClassName: 'embedded-auth-choice__skip-button', expanded: true, onClick: () => {
                            var _a, _b, _c;
                            ((_a = currentAction === null || currentAction === void 0 ? void 0 : currentAction.settings) === null || _a === void 0 ? void 0 : _a.goBack)
                                ? (_c = (_b = currentAction === null || currentAction === void 0 ? void 0 : currentAction.settings) === null || _b === void 0 ? void 0 : _b.goBack) === null || _c === void 0 ? void 0 : _c.call(_b)
                                : setShowAuthFlow(false);
                        }, copykey: 'dyn_embedded_authenticator.skip', children: t('dyn_embedded_authenticator.skip') })), (currentAction === null || currentAction === void 0 ? void 0 : currentAction.type) === 'helpSession' &&
                        (supportUrls || supportEmail) && (jsxRuntime.jsx("div", { className: 'embedded-auth-choice__support-links', children: jsxRuntime.jsx(SupportLinks.SupportLinks, { supportEmail: supportEmail, supportUrls: supportUrls }) }))] })] }));
};

exports.EmbeddedAuthChoice = EmbeddedAuthChoice;
