import { forceUpdate, h } from "@stencil/core";
import { DataTestIdsEnum } from "../../../constants/dataTestIds.enum";
import { EventBus } from "../../../utils/EventBus";
import { PendingTransactionsEventsEnum } from "./pending-transactions-modal.types";
export class PendingTransactionstModal {
    constructor() {
        this.eventBus = new EventBus();
        this.data = {
            isPending: false,
            title: '',
            subtitle: '',
        };
    }
    async getEventBus() {
        return this.eventBus;
    }
    render() {
        return (h("generic-modal", { key: '6b0d0c0baf8fb0e5d5ee1ea5306f3d0b0d609048', modalTitle: h("div", { "data-testid": DataTestIdsEnum.pendingTransactionsTitle }, this.data.title), modalSubtitle: h("div", { "data-testid": DataTestIdsEnum.pendingTransactionsSubtitle }, this.data.subtitle), onClose: () => this.close(), body: h("div", { class: "modal-body" }, h("button", { class: "close-button", onClick: () => this.close() }, "Close")) }));
    }
    close(props = { isUserClick: true }) {
        if (props.isUserClick) {
            this.eventBus.publish(PendingTransactionsEventsEnum.CLOSE);
        }
        if (this.hostElement && this.hostElement.parentNode) {
            this.hostElement.parentNode.removeChild(this.hostElement);
        }
    }
    dataUpdate(payload) {
        if (payload.shouldClose) {
            return this.close({ isUserClick: false });
        }
        this.data = Object.assign({}, payload);
        forceUpdate(this);
    }
    componentDidLoad() {
        this.eventBus.subscribe(PendingTransactionsEventsEnum.DATA_UPDATE, this.dataUpdate.bind(this));
    }
    disconnectedCallback() {
        this.eventBus.unsubscribe(PendingTransactionsEventsEnum.DATA_UPDATE, this.dataUpdate.bind(this));
    }
    static get is() { return "pending-transactions-modal"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["pending-transactions-modal.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["pending-transactions-modal.css"]
        };
    }
    static get properties() {
        return {
            "data": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "IPendingTransactionsModalData",
                    "resolved": "IPendingTransactionsModalData",
                    "references": {
                        "IPendingTransactionsModalData": {
                            "location": "import",
                            "path": "./pending-transactions-modal.types",
                            "id": "src/components/functional/pending-transactions-modal/pending-transactions-modal.types.ts::IPendingTransactionsModalData"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "{\n    isPending: false,\n    title: '',\n    subtitle: '',\n  }"
            }
        };
    }
    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"; }
}
//# sourceMappingURL=pending-transactions-modal.js.map
