'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 iconic = require('@dynamic-labs/iconic');
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
var Typography = require('../../../../components/Typography/Typography.cjs');
require('../../../../context/DynamicContext/DynamicContext.cjs');
require('../../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
require('@dynamic-labs/wallet-connector-core');
var ViewContext = 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('../../../../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');
var shortenEmail = require('../../../../shared/utils/functions/shortenEmail/shortenEmail.cjs');
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');
require('../../../../context/ThemeContext/ThemeContext.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('../../../../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');
var classNames = require('../../../../utils/functions/classNames/classNames.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');
var DotsMenu = require('../DotsMenu/DotsMenu.cjs');
require('../../../DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
var getPasskeyProviderFromUserAgent = require('../../helpers/getPasskeyProviderFromUserAgent.cjs');
require('@hcaptcha/react-hcaptcha');
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');
var PasskeyContext = 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('../DynamicWidgetHeader/DynamicWidgetHeader.cjs');
require('../../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
var getTimeSince = require('../../../../utils/functions/getTimeSince/getTimeSince.cjs');
require('../../views/CryptoComOnramp/CryptoComOnramp.cjs');
require('../../../../../index.cjs');
require('../../views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
require('../../../../store/state/tokenBalances.cjs');
require('../../../../store/state/multichainBalances.cjs');
var usePromptMfaAuth = require('../../../../utils/hooks/usePromptMfaAuth/usePromptMfaAuth.cjs');
require('../../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
var useDeletePasskey = require('../../../../utils/hooks/useDeletePasskey/useDeletePasskey.cjs');
var useInternalDynamicContext = require('../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
var isMfaMethodEnabled = require('../../../../utils/functions/isMfaMethodEnabled/isMfaMethodEnabled.cjs');

const mapPasskeyProviderToIcon = {
    android: jsxRuntime.jsx(iconic.AndroidIcon, {}),
    brave: jsxRuntime.jsx(iconic.BraveIcon, {}),
    chrome: jsxRuntime.jsx(iconic.ChromeIcon, {}),
    edge: jsxRuntime.jsx(iconic.EdgeIcon, {}),
    firefox: jsxRuntime.jsx(iconic.FirefoxIcon, {}),
    iPhone: jsxRuntime.jsx(iconic.AppleIcon, {}),
    opera: jsxRuntime.jsx(iconic.OperaIcon, {}),
    safari: jsxRuntime.jsx(iconic.SafariIcon, {}),
};
const PasskeyCard = ({ passkey, onUpdate }) => {
    var _a;
    const { t } = reactI18next.useTranslation();
    const { setShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
    const { pushView } = ViewContext.useViewContext();
    const { setPasskey, setPasskeyIcon } = PasskeyContext.usePasskeyContext();
    const deletePasskey = useDeletePasskey.useDeletePasskey();
    const promptMfaAuth = usePromptMfaAuth.usePromptMfaAuth();
    const menuOptions = [
        {
            Icon: null,
            callback: () => {
                setShowAuthFlow(true);
                setPasskey(passkey);
                setPasskeyIcon(() => { var _a; return (_a = PasskeyProviderIcon()) !== null && _a !== void 0 ? _a : undefined; });
                pushView('rename-passkey', { onUpdate });
            },
            copykey: 'dyn_manage_passkeys.passkey_rename',
            text: t('dyn_manage_passkeys.passkey_rename'),
        },
        {
            Icon: null,
            callback: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
                const isMfaRequired = isMfaMethodEnabled.isMfaMethodEnabled(sdkApiCore.MFADeviceType.Passkey);
                if (isMfaRequired) {
                    yield promptMfaAuth({ createMfaToken: true });
                }
                yield deletePasskey(passkey.id);
                onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate();
            }),
            copykey: 'dyn_manage_passkeys.passkey_delete',
            text: t('dyn_manage_passkeys.passkey_delete'),
        },
    ];
    const [showTooltip, setShowTooltip] = React.useState(false);
    const { value: timeSinceValue, unit: timeSinceUnit } = getTimeSince.getTimeSince(passkey.createdAt);
    const PasskeyProviderIcon = () => {
        if (!passkey.userAgent)
            return null;
        const provider = getPasskeyProviderFromUserAgent.getPasskeyProviderFromUserAgent(passkey.userAgent);
        if (!provider)
            return null;
        return mapPasskeyProviderToIcon[provider];
    };
    const getPasskeyProviderName = () => {
        if (!passkey.userAgent)
            return null;
        const provider = getPasskeyProviderFromUserAgent.getPasskeyProviderFromUserAgent(passkey.userAgent);
        if (!provider)
            return null;
        return t(`dyn_manage_passkeys.passkey_providers.${provider}`);
    };
    const handleShowTooltip = () => {
        setShowTooltip(true);
        setTimeout(() => {
            setShowTooltip(false);
        }, 2000);
    };
    return (jsxRuntime.jsxs("div", { className: 'passkey-card', children: [jsxRuntime.jsx("div", { className: 'passkey-card__info', children: jsxRuntime.jsxs("div", { className: 'passkey-card__info__text', children: [jsxRuntime.jsxs(Typography.Typography, { "data-testid": 'passkey-alias', variant: 'body_normal', color: 'primary', title: passkey.alias, onClick: handleShowTooltip, as: 'div', children: [jsxRuntime.jsxs("div", { className: 'passkey-card__body', children: [jsxRuntime.jsxs("div", { className: 'passkey-card__left', children: [jsxRuntime.jsx("div", { className: 'passkey-card__info__icon', "data-testid": 'provider-icon', children: jsxRuntime.jsx(PasskeyProviderIcon, {}) }), jsxRuntime.jsx("span", { className: 'passkey-card__info__alias', children: ((_a = passkey.alias) === null || _a === void 0 ? void 0 : _a.includes('@'))
                                                        ? shortenEmail.shortenEmail(passkey.alias, {
                                                            breakpoint: 12,
                                                            cutEnd: 4,
                                                            cutStart: 4,
                                                        })
                                                        : passkey.alias })] }), jsxRuntime.jsx(DotsMenu.DotsMenu, { options: menuOptions })] }), jsxRuntime.jsx("span", { className: classNames.classNames('passkey-card__info__tooltip', {
                                        'passkey-card__info__tooltip--visible': showTooltip,
                                    }), children: passkey.alias })] }), getPasskeyProviderName() && (jsxRuntime.jsxs(Typography.Typography, { variant: 'body_small', color: 'secondary', children: [t('dyn_manage_passkeys.passkey_from'), " ", getPasskeyProviderName()] }))] }) }), jsxRuntime.jsx("div", { className: 'passkey-card__date', children: jsxRuntime.jsxs(Typography.Typography, { variant: 'body_small', color: 'secondary', copykey: 'dyn_time_since.created', children: [t('dyn_time_since.created'), ' ', `${timeSinceValue} ${timeSinceUnit} ${t('dyn_time_since.ago')}`] }) })] }));
};

exports.PasskeyCard = PasskeyCard;
