'use client'
'use strict';

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

var _tslib = require('../../../../../../../_virtual/_tslib.cjs');
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var reactI18next = require('react-i18next');
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
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');
var chevronLeft = require('../../../../../shared/assets/chevron-left.cjs');
var exportPrivateKey = require('../../../../../shared/assets/export-private-key.cjs');
var exportRecoveryPhrase = require('../../../../../shared/assets/export-recovery-phrase.cjs');
require('../../../../../context/ViewContext/ViewContext.cjs');
var backupArrow = require('../../../../../shared/assets/backupArrow.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('../../../../../shared/consts/index.cjs');
require('../../../../../events/dynamicEvents.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');
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('../../../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
var ThemeContext = 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');
require('../../../../../utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs');
require('yup');
require('../../../../../context/MockContext/MockContext.cjs');
require('../../../../../views/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');
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('../../../../DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
require('@hcaptcha/react-hcaptcha');
var DynamicWidgetContext = require('../../../context/DynamicWidgetContext.cjs');
require('../../../helpers/convertExchangeKeyAndProviderEnum.cjs');
require('../../../../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.cjs');
require('../../../../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
require('../../../../../context/FooterAnimationContext/index.cjs');
require('../../../../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.cjs');
require('../../../../../context/PasskeyContext/PasskeyContext.cjs');
require('../../../../../context/OnrampContext/OnrampContext.cjs');
require('../../../../../store/state/sendBalances.cjs');
require('../../../../../store/state/connectorsInitializing/connectorsInitializing.cjs');
require('../../../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
require('../../../components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
require('../../../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
require('../../../components/PasskeyCard/PasskeyCard.cjs');
var useEmbeddedReveal = require('../../../../../utils/hooks/useEmbeddedReveal/useEmbeddedReveal.cjs');
require('../../CryptoComOnramp/CryptoComOnramp.cjs');
require('../../../../../../index.cjs');
require('../../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 EmbeddedWalletExportSection = () => {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
    const { t } = reactI18next.useTranslation();
    const { theme } = ThemeContext.useThemeContext();
    const { primaryWallet, user, projectSettings } = useInternalDynamicContext.useInternalDynamicContext();
    const { setDynamicWidgetView } = DynamicWidgetContext.useWidgetContext();
    const { getEOAWallet } = useSmartWallets.useSmartWallets();
    const { initPasskeyRecoveryProcess, shouldInitRecovery } = usePasskeyRecovery.usePasskeyRecovery();
    const { initExportProcess } = useEmbeddedReveal.useEmbeddedReveal();
    const eoaWallet = primaryWallet && getEOAWallet(primaryWallet);
    const wallet = eoaWallet !== null && eoaWallet !== void 0 ? eoaWallet : primaryWallet;
    const isEmbeddedWallet = Boolean(wallet &&
        (((_b = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.startsWith('turnkey')) ||
            ((_d = (_c = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _c === void 0 ? void 0 : _c.key) === null || _d === void 0 ? void 0 : _d.startsWith('dynamicwaas'))));
    const turnkeyWalletProperties = (_f = (_e = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _e === void 0 ? void 0 : _e.find(({ walletName, id }) => (walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey')) &&
        ((primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.id) ? id === (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.id) : true))) === null || _f === void 0 ? void 0 : _f.walletProperties;
    const isTurnkeyHDWallet = Boolean(turnkeyWalletProperties === null || turnkeyWalletProperties === void 0 ? void 0 : turnkeyWalletProperties.turnkeyHDWalletId);
    const isSessionKeyCompatible = (primaryWallet && walletConnectorCore.isSessionKeyCompatibleWallet(primaryWallet)) ||
        (eoaWallet && walletConnectorCore.isSessionKeyCompatibleWallet(eoaWallet));
    const handleExportClick = React.useCallback((recoveryPhrase) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
        if (!isSessionKeyCompatible) {
            if (yield shouldInitRecovery()) {
                yield initPasskeyRecoveryProcess(undefined, {
                    type: 'reveal',
                });
            }
        }
        return initExportProcess(recoveryPhrase);
    }), [
        shouldInitRecovery,
        initPasskeyRecoveryProcess,
        initExportProcess,
        isSessionKeyCompatible,
    ]);
    const handleExportButtonClick = React.useCallback(() => handleExportClick(), [handleExportClick]);
    const handleExportWithPhraseClick = React.useCallback(() => handleExportClick(true), [handleExportClick]);
    const exportIconClasses = React.useMemo(() => `settings-view__body__section__button__icon${theme.theme.name === 'dark' ? '__stroke' : ''}`, [theme.theme.name]);
    const isV3WaasWallet = Boolean(wallet && ((_h = (_g = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _g === void 0 ? void 0 : _g.key) === null || _h === void 0 ? void 0 : _h.startsWith('dynamicwaas')));
    const isGoogleDriveBackupEnabled = Boolean((_l = (_k = (_j = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _j === void 0 ? void 0 : _j.waas) === null || _k === void 0 ? void 0 : _k.backupOptions) === null || _l === void 0 ? void 0 : _l.includes(sdkApiCore.WaasBackupOptionsEnum.GoogleDrive));
    const shouldShowBackupOption = isV3WaasWallet && isGoogleDriveBackupEnabled;
    const handleBackupClick = React.useCallback(() => {
        setDynamicWidgetView('waas-backup');
    }, [setDynamicWidgetView]);
    if (!isEmbeddedWallet) {
        return null;
    }
    return (jsxRuntime.jsxs("div", { className: 'settings-view__body__section', children: [jsxRuntime.jsx("div", { className: 'settings-view__body__section__title', children: jsxRuntime.jsx(Typography.Typography, { copykey: 'dyn_settings.export_section.title', color: 'secondary', weight: 'medium', children: t('dyn_settings.export_section.title') }) }), jsxRuntime.jsx(TypographyButton.TypographyButton, { dataTestId: 'embedded-reveal-account-button', onClick: handleExportButtonClick, buttonClassName: 'settings-view__body__section__button', startSlot: 
                // eslint-disable-next-line react/jsx-wrap-multilines
                jsxRuntime.jsxs("div", { className: 'settings-view__body__section__button__start-slot', children: [jsxRuntime.jsx(exportPrivateKey.ReactComponent, { className: exportIconClasses }), jsxRuntime.jsx(Typography.Typography, { color: 'primary', weight: 'medium', copykey: 'dyn_settings.export_section.private_key_button', children: t('dyn_settings.export_section.private_key_button') })] }), endSlot: jsxRuntime.jsx(chevronLeft.ReactComponent, { className: 'settings-view__body__section__button__icon-secondary--rotate' }), showInternalLoading: false }), isTurnkeyHDWallet && (jsxRuntime.jsx(TypographyButton.TypographyButton, { dataTestId: 'embedded-reveal-button', onClick: handleExportWithPhraseClick, buttonClassName: 'settings-view__body__section__button', startSlot: 
                // eslint-disable-next-line react/jsx-wrap-multilines
                jsxRuntime.jsxs("div", { className: 'settings-view__body__section__button__start-slot', children: [jsxRuntime.jsx(exportRecoveryPhrase.ReactComponent, { className: exportIconClasses }), jsxRuntime.jsx(Typography.Typography, { color: 'primary', weight: 'medium', copykey: 'dyn_settings.export_section.srp_button', children: t('dyn_settings.export_section.srp_button') })] }), endSlot: jsxRuntime.jsx(chevronLeft.ReactComponent, { className: 'settings-view__body__section__button__icon-secondary--rotate' }), showInternalLoading: false })), shouldShowBackupOption && (jsxRuntime.jsx(TypographyButton.TypographyButton, { dataTestId: 'backup-button', onClick: handleBackupClick, buttonClassName: 'settings-view__body__section__button', startSlot: 
                // eslint-disable-next-line react/jsx-wrap-multilines
                jsxRuntime.jsxs("div", { className: 'settings-view__body__section__button__start-slot', children: [jsxRuntime.jsx(backupArrow.ReactComponent, { className: exportIconClasses }), jsxRuntime.jsx(Typography.Typography, { color: 'primary', weight: 'medium', copykey: 'dyn_settings.export_section.backup_button', children: t('dyn_settings.export_section.backup_button') })] }), endSlot: jsxRuntime.jsx(chevronLeft.ReactComponent, { className: 'settings-view__body__section__button__icon-secondary--rotate' }), showInternalLoading: false }))] }));
};

exports.EmbeddedWalletExportSection = EmbeddedWalletExportSection;
