'use strict';

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

const index = require('./index-9564483d.js');
const WalletConnectBase = require('./WalletConnectBase-89f60748.js');
require('./EventBus-1890a8f3.js');

const WalletConnect = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.data = {
            wcURI: '',
        };
        this.qrCodeSvg = '';
    }
    componentWillLoad() {
        this.walletConnectBase = new WalletConnectBase.WalletConnectBase(this.data);
    }
    async getEventBus() {
        return this.walletConnectBase.getEventBus();
    }
    async onDataChange(data) {
        if (data.wcURI) {
            this.qrCodeSvg = await this.walletConnectBase.generateSVG(data.wcURI);
        }
    }
    render() {
        return index.h("wallet-connect-body", { key: '4463e8a2720f42c2ad932f2280b2f53a24b51c2a', qrCodeSvg: this.qrCodeSvg, description: "Scan this QR using xPortal" });
    }
    removeComponent() {
        var _a;
        if ((_a = this.hostElement) === null || _a === void 0 ? void 0 : _a.parentNode) {
            this.hostElement.parentNode.removeChild(this.hostElement);
        }
    }
    componentDidLoad() {
        this.walletConnectBase.subscribeEventBus({
            closeFn: () => this.removeComponent(),
            forceUpdateFn: () => {
                // this is needed for the UI to be reactive
                this.data = this.walletConnectBase.data;
                index.forceUpdate(this);
            },
        });
    }
    disconnectedCallback() {
        this.walletConnectBase.unsubscribeEventBus({
            closeFn: () => this.removeComponent(),
            forceUpdateFn: () => {
                // this is needed for the UI to be reactive
                this.data = this.walletConnectBase.data;
                index.forceUpdate(this);
            },
        });
    }
    get hostElement() { return index.getElement(this); }
    static get watchers() { return {
        "data": ["onDataChange"]
    }; }
};

exports.wallet_connect = WalletConnect;

//# sourceMappingURL=wallet-connect.cjs.entry.js.map