import { forceUpdate, h } from "@stencil/core";
import { DataTestIdsEnum } from "../../../constants/dataTestIds.enum";
import { WalletConnectEventsEnum } from "./wallet-connect-modal.types";
import { WalletConnectBase } from "./WalletConnectBase";
export class WalletConnectModal {
    constructor() {
        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);
            },
        });
    }
    static get is() { return "wallet-connect-modal"; }
    static get encapsulation() { return "shadow"; }
    static get properties() {
        return {
            "data": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "IWalletConnectModalData",
                    "resolved": "IWalletConnectModalData",
                    "references": {
                        "IWalletConnectModalData": {
                            "location": "import",
                            "path": "./wallet-connect-modal.types",
                            "id": "src/components/functional/wallet-connect-components/wallet-connect-modal.types.ts::IWalletConnectModalData"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "{\n    wcURI: '',\n  }"
            }
        };
    }
    static get states() {
        return {
            "qrCodeSvg": {}
        };
    }
    static get methods() {
        return {
            "getEventBus": {
                "complexType": {
                    "signature": "() => Promise<IEventBus>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "IEventBus": {
                            "location": "import",
                            "path": "utils/EventBus",
                            "id": "src/utils/EventBus.ts::IEventBus"
                        }
                    },
                    "return": "Promise<IEventBus>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "hostElement"; }
    static get watchers() {
        return [{
                "propName": "data",
                "methodName": "onDataChange"
            }];
    }
}
//# sourceMappingURL=wallet-connect-modal.js.map
