'use strict';

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

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

const WalletConnectModal = 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("generic-modal", { key: '556e1f83ac53f2e200aca1816f91f917bc455d3d', modalTitle: index.h("div", { "data-testid": dataTestIds_enum.DataTestIdsEnum.walletConnetModalTitle }, "xPortal Mobile Wallet"), modalSubtitle: index.h("div", { "data-testid": dataTestIds_enum.DataTestIdsEnum.walletConnetModalSubtitle }, "Scan this QR code with your app"), onClose: () => this.close(), body: index.h("wallet-connect-body", { qrCodeSvg: this.qrCodeSvg }) }));
    }
    close(props = { isUserClick: true }) {
        if (props.isUserClick) {
            this.walletConnectBase.eventBus.publish(WalletConnectBase.WalletConnectEventsEnum.CLOSE);
        }
        if (this.hostElement && this.hostElement.parentNode) {
            this.hostElement.parentNode.removeChild(this.hostElement);
        }
    }
    componentDidLoad() {
        this.walletConnectBase.subscribeEventBus({
            closeFn: () => this.close({ isUserClick: false }),
            forceUpdateFn: () => {
                // this is needed for the UI to be reactive
                this.data = this.walletConnectBase.data;
                index.forceUpdate(this);
            },
        });
    }
    disconnectedCallback() {
        this.walletConnectBase.unsubscribeEventBus({
            closeFn: () => this.close({ isUserClick: false }),
            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_modal = WalletConnectModal;

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