var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { jsx as _jsx } from "react/jsx-runtime";
/* eslint-disable class-methods-use-this */
import "../css/network.css";
import { BaseNetworkSwitch } from "@web3auth/base";
import { createRoot } from "react-dom/client";
import AddNetwork from "./components/AddNetwork";
import SwitchNetwork from "./components/SwitchNetwork";
function createWrapper(id) {
    const element = document.getElementById(id || "w3a-network-container");
    if (element)
        return element;
    const wrapper = document.createElement("section");
    wrapper.setAttribute("id", id || "w3a-network-container");
    document.body.appendChild(wrapper);
    return wrapper;
}
export class NetworkSwitch extends BaseNetworkSwitch {
    addNetwork(params) {
        return __awaiter(this, void 0, void 0, function* () {
            const { chainConfig, appOrigin } = params;
            return new Promise((resolve, reject) => {
                const addNetworkCallback = () => {
                    return resolve(true);
                };
                const cancelCallback = () => {
                    return reject(new Error("User cancelled request for adding new network"));
                };
                const container = createWrapper("w3a-add-network-container");
                const networkRoot = createRoot(container);
                networkRoot.render(_jsx(AddNetwork, { appOrigin: appOrigin, chainConfig: chainConfig, onAddNetwork: addNetworkCallback, onCancelNetwork: cancelCallback }));
            });
        });
    }
    switchNetwork(params) {
        return __awaiter(this, void 0, void 0, function* () {
            const { currentChainConfig, appOrigin, newChainConfig } = params;
            return new Promise((resolve, reject) => {
                const switchNetworkCallback = () => {
                    return resolve(true);
                };
                const cancelCallback = () => {
                    return reject(new Error("User cancelled request for adding new network"));
                };
                const networkSwitchContainer = createWrapper("w3a-switch-network-container");
                const networkRoot = createRoot(networkSwitchContainer);
                networkRoot.render(_jsx(SwitchNetwork, { appOrigin: appOrigin, currentChainConfig: currentChainConfig, newChainConfig: newChainConfig, onSwitchNetwork: switchNetworkCallback, onCancelNetwork: cancelCallback }));
            });
        });
    }
    cancel() { }
}
//# sourceMappingURL=networkSwitch.js.map