import { r as registerInstance, h, f as forceUpdate, a as getElement } from './index-fb899b9a.js';
import { D as DataTestIdsEnum } from './dataTestIds.enum-55de9911.js';
import { W as WalletConnectBase, a as WalletConnectEventsEnum } from './WalletConnectBase-f88ac289.js';
import './EventBus-56ba7d6d.js';

const WalletConnectModal = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.data = {
            wcURI: '',
        };
        this.qrCodeSvg = '';
    }
    componentWillLoad() {
        this.walletConnectBase = new 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 (h("generic-modal", { key: '556e1f83ac53f2e200aca1816f91f917bc455d3d', modalTitle: h("div", { "data-testid": DataTestIdsEnum.walletConnetModalTitle }, "xPortal Mobile Wallet"), modalSubtitle: h("div", { "data-testid": DataTestIdsEnum.walletConnetModalSubtitle }, "Scan this QR code with your app"), onClose: () => this.close(), body: h("wallet-connect-body", { qrCodeSvg: this.qrCodeSvg }) }));
    }
    close(props = { isUserClick: true }) {
        if (props.isUserClick) {
            this.walletConnectBase.eventBus.publish(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;
                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;
                forceUpdate(this);
            },
        });
    }
    get hostElement() { return getElement(this); }
    static get watchers() { return {
        "data": ["onDataChange"]
    }; }
};

export { WalletConnectModal as wallet_connect_modal };

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