'use client'
'use strict';

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

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var createProviderHook = require('../../shared/utils/functions/createProviderHook/createProviderHook.cjs');
require('@dynamic-labs/sdk-api-core');
require('../../utils/constants/values.cjs');
require('@dynamic-labs/utils');
require('../../../../_virtual/_tslib.cjs');
require('@dynamic-labs/multi-wallet');
require('../../shared/logger.cjs');
require('react-international-phone');
require('../../utils/constants/colors.cjs');
require('@dynamic-labs/iconic');
require('@dynamic-labs/wallet-connector-core');
require('../ViewContext/ViewContext.cjs');
require('@dynamic-labs/wallet-book');
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 randomString = require('../../utils/functions/randomString/randomString.cjs');
require('@dynamic-labs/locale');
require('../../store/state/dynamicContextProps/dynamicContextProps.cjs');
require('../../store/state/primaryWalletId/primaryWalletId.cjs');
require('../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
require('../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');

const widgetRegistryContext = React.createContext(undefined);
const WidgetRegistryContextProvider = ({ children, }) => {
    const [registry, setRegistry] = React.useState({});
    const registerId = React.useCallback((widgetId, widgetType) => {
        setRegistry((prevRegistry) => (Object.assign(Object.assign({}, prevRegistry), { [widgetId]: {
                type: widgetType,
            } })));
    }, [setRegistry]);
    const removeId = React.useCallback((widgetId) => {
        setRegistry((prevRegistry) => {
            const newRegistry = Object.assign({}, prevRegistry);
            delete newRegistry[widgetId];
            return newRegistry;
        });
    }, [setRegistry]);
    const checkWidgetPresence = React.useCallback((widgetType) => Object.values(registry).some((widget) => widget.type === widgetType), [registry]);
    return (jsxRuntime.jsx(widgetRegistryContext.Provider, { value: { checkWidgetPresence, registerId, removeId }, children: children }));
};
const useWidgetRegistry = createProviderHook.createProviderHook(widgetRegistryContext, 'WidgetRegistryContextProvider');
const useRegisterWidget = (widgetType, enabled = true) => {
    const idRef = React.useRef(randomString.randomString(8));
    const { registerId, removeId } = useWidgetRegistry();
    React.useEffect(() => {
        if (enabled === false) {
            return;
        }
        registerId(idRef.current, widgetType);
        return () => {
            // This is disabled because eslint think we are using state value
            // but this is fine because it is a ref
            // eslint-disable-next-line react-hooks/exhaustive-deps
            removeId(idRef.current);
        };
    }, [widgetType, enabled, registerId, removeId]);
};
const useWidgetRegistryCheck = (widgetType) => {
    const { checkWidgetPresence } = useWidgetRegistry();
    return checkWidgetPresence(widgetType);
};

exports.WidgetRegistryContextProvider = WidgetRegistryContextProvider;
exports.useRegisterWidget = useRegisterWidget;
exports.useWidgetRegistryCheck = useWidgetRegistryCheck;
