import { jsx as _jsx } from "react/jsx-runtime";
import React from "react";
import * as ApiContext from "./api";
import * as NetworkContext from "./network";
import * as ConnectContext from "./connect";
import * as SubAccountContext from "./sub-account";
import * as Assets from "./assets";
const Context = React.createContext({
    aggregates: undefined,
});
const getKeys = (obj) => Object.keys(obj);
/**
 * @deprecated
 */
const withBrokenModule = (dest, modl, name, allow) => {
    let res = { ...dest };
    for (const key of getKeys(modl)) {
        res = Object.defineProperty(res, key, {
            get() {
                const message = `do not use ${String(key)} property of usePolkadot; hook is deprecated;${name && `use ${name} hook instead`}`;
                if (allow) {
                    console.error(message);
                    return modl[key];
                }
                throw new Error(message);
            },
        });
    }
    return res;
};
/**
 * @deprecated
 */
export const usePolkadot = () => {
    const stack = new Error().stack;
    React.useEffect(() => {
        console.log(stack);
        throw new Error("usePolkadot() hook is deprecated");
    }, []);
    const network = NetworkContext.useNetwork();
    const api = ApiContext.useApi();
    const accounts = ConnectContext.useAccounts();
    const subaccount = SubAccountContext.useAccount();
    const assets = Assets.useAssets();
    const stuff = React.useContext(Context);
    // breaking new module every day
    return withBrokenModule(withBrokenModule({
        ...stuff,
        ...api,
        ...accounts,
        ...subaccount,
    }, assets, "useAssets"), network, "useNetwork");
};
const Provider = ({ children }) => {
    const aggregates = React.useMemo(() => {
        return {};
    }, []);
    return (_jsx(Context.Provider, { value: {
            aggregates,
        }, children: children }));
};
export const PolkadotProvider = ({ children, useBase, ...props }) => (_jsx(NetworkContext.NetworkProvider, { networks: props.networks, children: _jsx(ApiContext.ApiProvider, { useBase: useBase, children: _jsx(ConnectContext.ConnectProvider, { name: props.name, useBase: useBase, children: _jsx(SubAccountContext.SubAccountProvider, { useBase: useBase, children: _jsx(Assets.AssetsProvider, { isDebug: props.isDebug, children: _jsx(Provider, { children: children }) }) }) }) }) }));
//# sourceMappingURL=context.js.map