'use client'
'use strict';

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

var _tslib = require('../../../../../_virtual/_tslib.cjs');
var React = require('react');
var walletBook = require('@dynamic-labs/wallet-book');
var data = require('../../../views/WalletList/data.cjs');
require('@dynamic-labs/sdk-api-core');
require('../../constants/values.cjs');
require('@dynamic-labs/utils');
require('@dynamic-labs/multi-wallet');
require('../../../shared/logger.cjs');
require('react-international-phone');
require('../../constants/colors.cjs');
require('@dynamic-labs/iconic');
require('@dynamic-labs/wallet-connector-core');
require('react/jsx-runtime');
require('../../../context/ViewContext/ViewContext.cjs');
require('../../../shared/consts/index.cjs');
require('../../../store/state/nonce/nonce.cjs');
require('@dynamic-labs-wallet/browser-wallet-client');
require('@dynamic-labs-sdk/client/core');
require('eventemitter3');
require('@dynamic-labs-sdk/client');
require('../../../config/ApiEndpoint.cjs');
require('../../../events/dynamicEvents.cjs');
var serializeWalletConnectors = require('../../functions/serializeWalletConnectors/serializeWalletConnectors.cjs');
require('@dynamic-labs/locale');
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
require('../../functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');
var walletOptions = require('../../../store/state/walletOptions/walletOptions.cjs');
var settingsUtils = require('../../../store/utils/settingsUtils/settingsUtils.cjs');
var verifyRequiredConnectorsAreSetup = require('./utils/verifyRequiredConnectorsAreSetup/verifyRequiredConnectorsAreSetup.cjs');

const useCreateWalletConnectorOptions = (_a) => {
    var { projectSettings, networkConfigurations, walletBook: walletBook$1, walletConnectorsProp, walletConnectorExtensions } = _a, props = _tslib.__rest(_a, ["projectSettings", "networkConfigurations", "walletBook", "walletConnectorsProp", "walletConnectorExtensions"]);
    const redirectUrl = settingsUtils.useRedirectUrl();
    const walletConnectorsKey = React.useMemo(() => { var _a; return (_a = serializeWalletConnectors.serializeWalletConnectors(walletConnectorsProp)) === null || _a === void 0 ? void 0 : _a.join(','); }, [walletConnectorsProp]);
    const isWalletBookLoaded = React.useMemo(() => walletBook.isWalletBookPopulated(walletBook$1), [walletBook$1]);
    // networkConfigurations can get a fresh object identity on every render even when
    // its content is unchanged (e.g. built inline upstream, churned by a host-app
    // re-render storm). Depending on a stable content signature instead of the object
    // reference keeps a render storm from rebuilding the (potentially 100s-strong)
    // connector list every frame — mirrors walletConnectorsKey above.
    const networkConfigurationsKey = React.useMemo(() => JSON.stringify(networkConfigurations !== null && networkConfigurations !== void 0 ? networkConfigurations : {}), [networkConfigurations]);
    const walletConnectorOptions = React.useMemo(() => {
        if (!projectSettings || !isWalletBookLoaded || !networkConfigurations)
            return [];
        return data.getWallets({
            getSupportedWalletOpts: Object.assign({ networkConfigurations,
                redirectUrl, settings: projectSettings, skipMemo: true, walletBook: walletBook$1, walletConnectorsProp: walletConnectorsProp !== null && walletConnectorsProp !== void 0 ? walletConnectorsProp : [] }, props),
            walletConnectorExtensions,
        });
        // walletUiUtils is intentionally excluded (its unstable identity would cause an
        // infinite loop); networkConfigurations is depended on via its content signature
        // (networkConfigurationsKey) so an identity-only churn doesn't rebuild the list.
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [
        projectSettings,
        redirectUrl,
        walletConnectorsKey,
        isWalletBookLoaded,
        networkConfigurationsKey,
    ]);
    React.useEffect(() => {
        if (!projectSettings || walletConnectorOptions.length === 0)
            return;
        verifyRequiredConnectorsAreSetup.verifyRequiredConnectorsAreSetup(projectSettings, walletConnectorOptions.map(({ walletConnector }) => walletConnector));
        walletOptions.mergeWalletConnectorOptions(walletConnectorOptions);
    }, [walletConnectorOptions, projectSettings]);
    return { walletConnectorOptions };
};

exports.useCreateWalletConnectorOptions = useCreateWalletConnectorOptions;
