'use client'
import { jsx } from 'react/jsx-runtime';
import { createContext, useState, useRef, useCallback, cloneElement } from 'react';
import { createProviderHook } from '../../shared/utils/functions/createProviderHook/createProviderHook.js';
import '@dynamic-labs/sdk-api-core';
import '../../utils/constants/values.js';
import '@dynamic-labs/utils';
import '../../../../_virtual/_tslib.js';
import '@dynamic-labs/multi-wallet';
import '../../shared/logger.js';
import 'react-international-phone';
import '../../utils/constants/colors.js';
import '@dynamic-labs/iconic';
import '@dynamic-labs/wallet-connector-core';
import '../ViewContext/ViewContext.js';
import '@dynamic-labs/wallet-book';
import '../../shared/consts/index.js';
import '../../store/state/nonce/nonce.js';
import '@dynamic-labs-wallet/browser-wallet-client';
import '@dynamic-labs-sdk/client/core';
import 'eventemitter3';
import '@dynamic-labs-sdk/client';
import '../../config/ApiEndpoint.js';
import '../../events/dynamicEvents.js';
import { randomString } from '../../utils/functions/randomString/randomString.js';
import '@dynamic-labs/locale';
import '../../store/state/dynamicContextProps/dynamicContextProps.js';
import '../../store/state/primaryWalletId/primaryWalletId.js';
import '../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
import '../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';

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

export { ReinitializeContextProvider, useReinitialize, useReinitializeState };
