'use client'
'use strict';

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

var utils = require('@dynamic-labs/utils');
require('../../../context/DynamicContext/useDynamicContext/useDynamicContext.cjs');
var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
var UserWalletsContext = require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
var walletOptions = require('../../../store/state/walletOptions/walletOptions.cjs');
var index = require('../../functions/walletFilters/index.cjs');
var walletListBuilder = require('../../functions/walletListBuilder/walletListBuilder.cjs');
var getEffectiveRecommendedWallets = require('./utils/getEffectiveRecommendedWallets/getEffectiveRecommendedWallets.cjs');
var getEffectiveWalletFilter = require('./utils/getEffectiveWalletFilter/getEffectiveWalletFilter.cjs');

const useWalletList = ({ isWalletConnectList = false, viewWalletsFilter, searchFilter, lastUsedWalletKey, }) => {
    const { walletsFilter, walletConnectorOptions, defaultNumberOfWalletsToShow, bridgeChainsToConnect, multiWallet, recommendedWallets, selectedTabSettings, } = useInternalDynamicContext.useInternalDynamicContext();
    const { userWallets } = UserWalletsContext.useInternalUserWallets();
    const walletGroups = walletOptions.useWalletGroups();
    const getFilteredBridgeChains = (bridgeChainsToConnect === null || bridgeChainsToConnect === void 0 ? void 0 : bridgeChainsToConnect.length) &&
        index.FilterBridgeChainsName(bridgeChainsToConnect[0].chain);
    const filteredBridgeChains = getFilteredBridgeChains && getFilteredBridgeChains(walletConnectorOptions);
    const effectiveRecommendedWallets = getEffectiveRecommendedWallets.getEffectiveRecommendedWallets(selectedTabSettings, recommendedWallets);
    const effectiveWalletsFilter = getEffectiveWalletFilter.getEffectiveWalletFilter(selectedTabSettings, walletsFilter);
    const { numberOfWallets, walletsList } = walletListBuilder.walletListBuilder({
        groupWallets: true,
        inputList: filteredBridgeChains || walletConnectorOptions,
        isWalletConnectList,
        lastUsedWalletKey,
        multiWallet,
        numberOfWalletsToShow: defaultNumberOfWalletsToShow,
        recommendedWallets: effectiveRecommendedWallets,
        searchFilter,
        showMoreWalletsWithFilter: true,
        userWallets,
        walletGroups,
        // use both filters if available, else use the viewWalletsFilter or effectiveWalletsFilter
        walletsFilter: viewWalletsFilter && effectiveWalletsFilter
            ? utils.pipe(viewWalletsFilter).pipe(effectiveWalletsFilter)
            : viewWalletsFilter || effectiveWalletsFilter,
    });
    return {
        numberOfWallets,
        recommendedWallets: effectiveRecommendedWallets,
        walletsList,
    };
};

exports.useWalletList = useWalletList;
