'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 utils = require('@dynamic-labs/utils');
var noWalletFound = require('../../assets/no-wallet-found.cjs');
var classNames = require('../../utils/functions/classNames/classNames.cjs');
require('../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
require('@dynamic-labs/iconic');
require('../../context/ViewContext/ViewContext.cjs');
require('../../../../_virtual/_tslib.cjs');
require('@dynamic-labs/wallet-connector-core');
require('../../shared/logger.cjs');
require('@dynamic-labs/wallet-book');
var localStorage = require('../../utils/constants/localStorage.cjs');
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');
var ErrorContext = 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 useProjectSettings = require('../../client/extension/projectSettings/useProjectSettings/useProjectSettings.cjs');
require('@dynamic-labs/locale');
var dynamicContextProps = 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');
var UserWalletsContext = 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');
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('../CollectUserDataView/useFields.cjs');
require('../../context/FieldsStateContext/FieldsStateContext.cjs');
require('../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
require('@dynamic-labs/rpc-providers');
var walletOptions = 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');
var Skeleton = require('../../components/Skeleton/Skeleton.cjs');
var WalletListItem = require('../WalletList/WalletListItem/WalletListItem.cjs');
require('../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
require('react-focus-lock');
require('../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
var ErrorContainer = require('../../components/ErrorContainer/ErrorContainer.cjs');
require('../../components/IconButton/IconButton.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');
var OnrampContext = require('../../context/OnrampContext/OnrampContext.cjs');
require('../../../index.cjs');
require('../../context/WalletGroupContext/WalletGroupContext.cjs');
var walletListBuilder = require('../../utils/functions/walletListBuilder/walletListBuilder.cjs');
var convertExchangeKeyAndProviderEnum = require('../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.cjs');
require('qrcode');
require('../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
var Search = require('../../components/Search/Search.cjs');
var DefaultFooter = require('../../layout/DynamicAuthLayout/DefaultFooter/DefaultFooter.cjs');
var SearchNotFoundMessage = require('../WalletList/SearchNotFoundMessage/SearchNotFoundMessage.cjs');
require('../../context/IpConfigurationContext/IpConfigurationContext.cjs');
require('../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
require('../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
require('@hcaptcha/react-hcaptcha');
var ExchangeListItem = require('../ExchangeList/ExchangeListItem/ExchangeListItem.cjs');
require('../ExchangeWhitelistWarning/ExchangeWhitelistWarning.cjs');
require('../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
require('../MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.cjs');
var OnRampItem = require('./OnRampItem/OnRampItem.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 UnifiedList = ({ onSelectWallet, onSelectExchange, onSelectOnRamp, showDefaultFooter, scrollContainerClassName, }) => {
    var _a, _b, _c;
    const { t } = reactI18next.useTranslation();
    const { error } = ErrorContext.useErrorContext();
    const [footerBorderIsVisible, setFooterBorderIsVisible] = React.useState(true);
    const [filterValue, setFilterValue] = React.useState((_a = utils.StorageService.getItem(localStorage.WALLET_PICKER_SEARCH_KEY)) !== null && _a !== void 0 ? _a : '');
    const { userWallets } = UserWalletsContext.useInternalUserWallets();
    const walletGroups = walletOptions.useWalletGroups();
    const { multiWallet, walletConnectorOptions } = useInternalDynamicContext.useInternalDynamicContext();
    const { enabledOnrampProviders } = OnrampContext.useOnrampContext();
    const dynamicSettings = dynamicContextProps.useDynamicSettings();
    const { numberOfWallets, walletsList } = walletListBuilder.walletListBuilder({
        groupWallets: true,
        inputList: walletConnectorOptions,
        isWalletConnectList: false,
        lastUsedWalletKey: (_b = utils.StorageService.getItem(localStorage.LAST_USED_WALLET)) !== null && _b !== void 0 ? _b : undefined,
        loginWithEmail: true,
        multiWallet,
        numberOfWalletsToShow: (_c = dynamicSettings.defaultNumberOfWalletsToShow) !== null && _c !== void 0 ? _c : 10,
        recommendedWallets: dynamicSettings.recommendedWallets,
        searchFilter: filterValue,
        userWallets,
        walletGroups,
        walletsFilter: dynamicSettings.walletsFilter,
    });
    const projectSettings = useProjectSettings.useProjectSettings();
    const exchangeNames = React.useMemo(() => {
        if (!(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.exchanges))
            return [];
        const names = projectSettings.exchanges.flatMap(({ exchange, enabledAt }) => {
            if (!enabledAt)
                return [];
            return [convertExchangeKeyAndProviderEnum.convertExchangeKeytoProviderEnum(exchange)];
        });
        return [...new Set(names)];
    }, [projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.exchanges]);
    const filteredExchanges = React.useMemo(() => {
        const term = filterValue.trim().toLowerCase();
        if (!term)
            return exchangeNames;
        return exchangeNames.filter((provider) => convertExchangeKeyAndProviderEnum.convertProviderToExchangeKeyEnum(provider).toLowerCase().includes(term));
    }, [exchangeNames, filterValue]);
    const onrampOptions = React.useMemo(() => enabledOnrampProviders.filter(({ isPaymentMethod }) => !isPaymentMethod), [enabledOnrampProviders]);
    const filteredOnramp = React.useMemo(() => {
        const term = filterValue.trim().toLowerCase();
        if (!term)
            return onrampOptions;
        return onrampOptions.filter(({ displayName }) => displayName.toLowerCase().includes(term));
    }, [onrampOptions, filterValue]);
    const scrollRef = React.useRef(null);
    const handleScroll = () => {
        const el = scrollRef.current;
        if (!el)
            return;
        setFooterBorderIsVisible(el.scrollTop <= el.clientHeight * 1.25);
    };
    const handleFilterChange = (value) => {
        utils.StorageService.setItem(localStorage.WALLET_PICKER_SEARCH_KEY, value);
        setFilterValue(value);
    };
    const isLoading = !projectSettings;
    const walletTrailing = (jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', color: 'tertiary', copykey: 'dyn_unified_list.wallet', children: t('dyn_unified_list.wallet') }));
    const exchangeTrailing = (jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', color: 'tertiary', copykey: 'dyn_unified_list.exchange', children: t('dyn_unified_list.exchange') }));
    const onrampTrailing = (jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', color: 'tertiary', copykey: 'dyn_unified_list.onramp', children: t('dyn_unified_list.onramp') }));
    return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: classNames.classNames('unified-list__search-container', {
                    'unified-list__search-container--scroll': !error,
                }), children: jsxRuntime.jsx(Search.Search, { copykey: 'dyn_unified_list.search.label', label: t('dyn_unified_list.search.label', {
                        count: numberOfWallets + filteredExchanges.length,
                    }), value: filterValue, onChange: ({ target: { value } }) => handleFilterChange(value), onClickClear: () => handleFilterChange('') }) }), Boolean(error) && (jsxRuntime.jsx(ErrorContainer.ErrorContainer, { className: 'unified-list__error-container', withIcon: false, children: error })), jsxRuntime.jsx("div", { className: classNames.classNames('unified-list__scroll-container', scrollContainerClassName, { 'unified-list__scroll-container--error': Boolean(error) }), ref: scrollRef, onScroll: handleScroll, "data-testid": 'unified-list-scroll-container', children: isLoading ? (jsxRuntime.jsx(Skeleton.Skeleton, { count: 10, className: 'unified-list__tile-skeleton' })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [walletsList.length === 0 &&
                            filteredExchanges.length === 0 &&
                            filteredOnramp.length === 0 &&
                            (walletConnectorOptions.length ||
                                exchangeNames.length ||
                                onrampOptions.length) ? (jsxRuntime.jsx(SearchNotFoundMessage.SearchNotFoundMessage, { titleKey: t('dyn_unified_list.search.not_found.title'), subtitleKey: t('dyn_unified_list.search.not_found.description'), image: jsxRuntime.jsx(noWalletFound.ReactComponent, {}) })) : (walletsList.map((wallet, idx) => (jsxRuntime.jsx(WalletListItem.WalletListItem, { wallet: wallet, onResetSearchValue: () => handleFilterChange(''), recommendedWallets: dynamicSettings.recommendedWallets, onSelectWallet: onSelectWallet, trailingProp: walletTrailing }, `wallet_${wallet.key}_${idx}`)))), filteredExchanges.map((prov, idx) => (jsxRuntime.jsx(ExchangeListItem.ExchangeListItem, { exchange: convertExchangeKeyAndProviderEnum.convertProviderToExchangeKeyEnum(prov), onResetSearchValue: () => handleFilterChange(''), onSelectExchange: onSelectExchange, trailingProp: exchangeTrailing }, `exchange_${prov}_${idx}`))), filteredOnramp.map((onramp, idx) => (jsxRuntime.jsx(OnRampItem.OnRampItem, { onramp: onramp, onResetSearchValue: () => handleFilterChange(''), onSelectOnRamp: onSelectOnRamp, trailingProp: onrampTrailing }, `onramp_${onramp}_${idx}`)))] })) }), showDefaultFooter && (jsxRuntime.jsx(DefaultFooter.DefaultFooter, { hideBorder: !footerBorderIsVisible }))] }));
};

exports.UnifiedList = UnifiedList;
