'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 useReinitializeState = () => {
    const [key, setKey] = React.useState();
    return { key, setKey };
};
const reinitializeContext = React.createContext(undefined);
/**
 * Provider that provides a reinitialize function to its children.
 * @param children The children to render.
 * @param onReinitialize A callback that is called when reinitialize is called.
 */
const ReinitializeContextProvider = ({ children, onReinitialize, reinitializeState }) => {
    const onReinitializeCallbackRef = React.useRef(onReinitialize);
    onReinitializeCallbackRef.current = onReinitialize;
    const reinitialize = React.useCallback(() => {
        var _a;
        const newKey = randomString.randomString(8);
        (_a = onReinitializeCallbackRef.current) === null || _a === void 0 ? void 0 : _a.call(onReinitializeCallbackRef, newKey);
        reinitializeState.setKey(newKey);
    }, []);
    return (jsxRuntime.jsx(reinitializeContext.Provider, { value: { key: reinitializeState.key, reinitialize }, children: React.cloneElement(children, { key: reinitializeState.key }) }));
};
/**
 * Custom hook that provides an reinitialize function for the DynamicContextProvider.
 * @returns The reinitialize function.
 */
const useReinitializeContext = createProviderHook.createProviderHook(reinitializeContext, 'ReinitializeContextProvider');
const useReinitialize = () => useReinitializeContext().reinitialize;

exports.ReinitializeContextProvider = ReinitializeContextProvider;
exports.useReinitialize = useReinitialize;
exports.useReinitializeState = useReinitializeState;
