'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 utils = require('@dynamic-labs/utils');
require('../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
var deleteEmbeddedHero = require('../../shared/assets/delete-embedded-hero.cjs');
require('@dynamic-labs/iconic');
require('../../context/ViewContext/ViewContext.cjs');
require('@dynamic-labs/wallet-connector-core');
require('../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
require('../../utils/constants/colors.cjs');
require('../../utils/constants/values.cjs');
require('@dynamic-labs/sdk-api-core');
require('../../shared/consts/index.cjs');
require('../../components/Alert/Alert.cjs');
require('../../events/dynamicEvents.cjs');
require('../../context/DynamicContext/DynamicContext.cjs');
require('../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
require('../../store/state/authMode/authMode.cjs');
var useInternalDynamicContext = require('../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.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');
var embeddedWallets = require('../../data/api/embeddedWallets/embeddedWallets.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('../../context/VerificationContext/VerificationContext.cjs');
require('react-dom');
require('../../utils/functions/compareChains/compareChains.cjs');
require('../Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
var getTurnkeyWalletId = require('../../utils/functions/getTurnkeyWalletId/getTurnkeyWalletId.cjs');
require('../../context/ThemeContext/ThemeContext.cjs');
var useSmartWallets = require('../../utils/hooks/useSmartWallets/useSmartWallets.cjs');
require('../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.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('../CollectUserDataView/useFields.cjs');
require('../../context/FieldsStateContext/FieldsStateContext.cjs');
require('../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
require('@dynamic-labs/rpc-providers');
require('../../store/state/walletOptions/walletOptions.cjs');
var Typography = require('../../components/Typography/Typography.cjs');
require('../../context/FooterAnimationContext/index.cjs');
require('../../components/ShadowDOM/ShadowDOM.cjs');
require('../../components/Transition/ZoomTransition/ZoomTransition.cjs');
require('../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
require('../../components/Transition/OpacityTransition/OpacityTransition.cjs');
require('../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
require('../../context/WalletGroupContext/WalletGroupContext.cjs');
require('../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
require('react-focus-lock');
require('../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
var Checkbox = require('../../components/Checkbox/Checkbox.cjs');
var ErrorContainer = require('../../components/ErrorContainer/ErrorContainer.cjs');
require('../../components/IconButton/IconButton.cjs');
var TypographyButton = require('../../components/TypographyButton/TypographyButton.cjs');
var getProperErrorMessage = require('../../modals/SignMessageConfirmationModal/getProperErrorMessage.cjs');
require('../../components/MenuList/Dropdown/Dropdown.cjs');
require('formik');
require('../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
require('../../store/state/sendBalances.cjs');
require('../../components/Input/Input.cjs');
require('../../components/OverlayCard/OverlayCard.cjs');
require('../TransactionConfirmationView/TransactionConfirmationView.cjs');
require('../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
require('../../context/PasskeyContext/PasskeyContext.cjs');
require('../../widgets/DynamicWidget/components/PasskeyCard/PasskeyCard.cjs');
require('../../widgets/DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.cjs');
require('../../context/OnrampContext/OnrampContext.cjs');
require('../../../index.cjs');
require('../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.cjs');
require('qrcode');
require('../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.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('../ExchangeWhitelistWarning/ExchangeWhitelistWarning.cjs');
require('../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
require('../MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.cjs');
require('../../store/state/connectorsInitializing/connectorsInitializing.cjs');
require('../../store/state/tokenBalances.cjs');
require('../../store/state/multichainBalances.cjs');
require('../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
require('../../components/InlineWidget/InlineWidget.cjs');
require('../../components/IsBrowser/IsBrowser.cjs');
require('../../components/Popper/Popper/Popper.cjs');
require('../../components/Popper/PopperContext/PopperContext.cjs');

const EmbeddedDeleteView = () => {
    const { primaryWallet, setShowAuthFlow, environmentId, handleLogOut, user } = useInternalDynamicContext.useInternalDynamicContext();
    const [isAcknowledgementChecked, setIsAcknowledgementChecked] = React.useState(false);
    const [error, setError] = React.useState(undefined);
    const { t } = reactI18next.useTranslation();
    const [isLoading, setIsLoading] = React.useState(false);
    const { isSmartWallet, getEOAWallet } = useSmartWallets.useSmartWallets();
    const errorText = React.useMemo(() => {
        if (!error) {
            return undefined;
        }
        if (error instanceof utils.DynamicError) {
            return error.message;
        }
        try {
            return getProperErrorMessage.getProperErrorMessage(error, user);
        }
        catch (e) {
            return 'An unexpected error occured while deleting your embedded wallets.';
        }
    }, [error, user]);
    const handleDeleteEmbeddedWallets = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
        var _a;
        if (!primaryWallet) {
            return;
        }
        setIsLoading(true);
        try {
            const primaryTurnkeyWalletId = getTurnkeyWalletId.getTurnkeyWalletId(primaryWallet.id, (user === null || user === void 0 ? void 0 : user.verifiedCredentials) || []);
            const deleteEmbeddedWalletsRawPayload = yield embeddedWallets.getDeleteEmbeddedWalletsRequest({
                environmentId,
                walletId: primaryTurnkeyWalletId,
            });
            const connector = isSmartWallet(primaryWallet)
                ? (_a = getEOAWallet(primaryWallet)) === null || _a === void 0 ? void 0 : _a.connector
                : primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector;
            const signedDeleteWalletsRequest = yield connector.stampDeleteSubOrganizationRequest({
                request: deleteEmbeddedWalletsRawPayload,
            });
            yield embeddedWallets.deleteEmbeddedWallets({
                deleteEmbeddedWalletsRequest: signedDeleteWalletsRequest,
                environmentId,
            });
            handleLogOut();
        }
        catch (error) {
            setError(error);
        }
        finally {
            setIsLoading(false);
        }
    });
    const contentHeader = (jsxRuntime.jsx("div", { children: jsxRuntime.jsx("div", { className: 'embedded-delete-view__body__description', children: jsxRuntime.jsx("div", { className: 'embedded-delete-view__header', children: jsxRuntime.jsx(deleteEmbeddedHero.ReactComponent, {}) }) }) }));
    return (jsxRuntime.jsxs("div", { className: 'embedded-delete-view', children: [jsxRuntime.jsx("div", { className: 'embedded-delete-view__body', children: contentHeader }), errorText && jsxRuntime.jsx(ErrorContainer.ErrorContainer, { children: errorText }), jsxRuntime.jsxs("div", { className: 'embedded-delete-view__body__card', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', color: 'primary', style: { letterSpacing: '-0.15px' }, copykey: 'dyn_embedded_delete.description_1', children: t('dyn_embedded_delete.description_1') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', color: 'primary', style: { fontWeight: 'bold', letterSpacing: '-0.15px' }, copykey: 'dyn_embedded_delete.description_2', children: t('dyn_embedded_delete.description_2') })] }), jsxRuntime.jsx("div", { className: 'embedded-delete-view__body__confirm_card', children: jsxRuntime.jsxs("button", { className: 'embedded-delete-view__body__card__acknowledgement', "data-testid": 'embedded-delete-checkbox', onClick: () => setIsAcknowledgementChecked(!isAcknowledgementChecked), children: [jsxRuntime.jsx("div", { children: jsxRuntime.jsx(Checkbox.Checkbox, { checked: isAcknowledgementChecked, className: 'embedded-delete-view__body__card__statement__checkbox', id: 'embedded-reveal-checkbox-1' }) }), jsxRuntime.jsx("div", { children: jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', color: 'primary', style: { letterSpacing: '-0.15px' }, copykey: 'dyn_embedded_delete.acknowledgement', children: t('dyn_embedded_delete.acknowledgement') }) })] }) }), jsxRuntime.jsxs("div", { className: 'embedded-delete-view__body__cta_button_wrapper', children: [jsxRuntime.jsx(TypographyButton.TypographyButton, { buttonPadding: 'large', buttonVariant: 'primary', typographyProps: {
                            color: 'inherit',
                        }, onClick: () => setShowAuthFlow(false), disabled: false, loading: false, dataTestId: 'embedded-delete-cancel-button', copykey: 'dyn_embedded_delete.cancel_button', buttonClassName: 'embedded-delete-view__body__button', children: t('dyn_embedded_delete.cancel_button') }), jsxRuntime.jsx(TypographyButton.TypographyButton, { buttonPadding: 'large', buttonVariant: 'brand-primary', typographyProps: {
                            color: 'inherit',
                            style: {
                                fontSize: '13px',
                            },
                        }, onClick: handleDeleteEmbeddedWallets, disabled: isLoading || !isAcknowledgementChecked, loading: isLoading, dataTestId: 'embedded-delete-action-button', copykey: 'dyn_embedded_delete.action_button', buttonClassName: 'embedded-delete-view__body__button', children: t('dyn_embedded_delete.action_button') })] })] }));
};

exports.EmbeddedDeleteView = EmbeddedDeleteView;
