import { forceUpdate, h } from "@stencil/core";
import { WalletConnectEventsEnum } from "../wallet-connect.types";
import { WalletConnectBase } from "../WalletConnectBase";
export class WalletConnectProvider {
    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("mvx-wallet-connect-flow", { key: 'aec3491440c3ebb2c60452b572c06bd73ff5a65e', qrCodeSvg: this.qrCodeSvg });
    }
    removeComponent() {
        var _a;
        if ((_a = this.hostElement) === null || _a === void 0 ? void 0 : _a.parentNode) {
            this.hostElement.parentNode.removeChild(this.hostElement);
        }
    }
    getEventSubscription() {
        return {
            closeFn: () => this.removeComponent(),
            forceUpdateFn: () => {
                this.data = this.walletConnectBase.data;
                forceUpdate(this);
            },
        };
    }
    componentDidLoad() {
        this.walletConnectBase.subscribeEventBus(this.getEventSubscription());
    }
    disconnectedCallback() {
        this.walletConnectBase.eventBus.publish(WalletConnectEventsEnum.UI_DISCONNECTED);
        this.walletConnectBase.unsubscribeEventBus(this.getEventSubscription());
    }
    static get is() { return "mvx-wallet-connect-provider"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["wallet-connect-provider.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["wallet-connect-provider.css"]
        };
    }
    static get properties() {
        return {
            "data": {
                "type": "unknown",
                "attribute": "data",
                "mutable": false,
                "complexType": {
                    "original": "IWalletConnectPanelData",
                    "resolved": "IWalletConnectPanelData",
                    "references": {
                        "IWalletConnectPanelData": {
                            "location": "import",
                            "path": "../wallet-connect.types",
                            "id": "src/components/functional/wallet-connect/wallet-connect.types.ts::IWalletConnectPanelData"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "{ wcURI: '' }"
            }
        };
    }
    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-provider.js.map
