import { forceUpdate, h } from "@stencil/core";
import { WalletConnectBase } from "./WalletConnectBase";
export class WalletConnect {
    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("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;
                forceUpdate(this);
            },
        });
    }
    disconnectedCallback() {
        this.walletConnectBase.unsubscribeEventBus({
            closeFn: () => this.removeComponent(),
            forceUpdateFn: () => {
                // this is needed for the UI to be reactive
                this.data = this.walletConnectBase.data;
                forceUpdate(this);
            },
        });
    }
    static get is() { return "wallet-connect"; }
    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.js.map
