import { forceUpdate, h } from "@stencil/core";
import { DataTestIdsEnum } from "../../../constants/dataTestIds.enum";
import { EventBus } from "../../../utils/EventBus";
import { PendingTransactionsEventsEnum } from "./pending-transactions-panel.types";
export class PendingTransactionstPanel {
    constructor() {
        this.eventBus = new EventBus();
        this.isOpen = false;
        this.data = {
            isPending: false,
            title: '',
            subtitle: '',
        };
    }
    componentDidLoad() {
        this.eventBus.subscribe(PendingTransactionsEventsEnum.DATA_UPDATE, this.dataUpdate.bind(this));
        this.eventBus.subscribe(PendingTransactionsEventsEnum.OPEN_PENDING_TRANSACTIONS_PANEL, this.handleOpen.bind(this));
        this.eventBus.subscribe(PendingTransactionsEventsEnum.CLOSE_PENDING_TRANSACTIONS, this.onClose.bind(this, { isUserClick: false }));
    }
    disconnectedCallback() {
        this.eventBus.unsubscribe(PendingTransactionsEventsEnum.DATA_UPDATE, this.dataUpdate.bind(this));
        this.eventBus.unsubscribe(PendingTransactionsEventsEnum.OPEN_PENDING_TRANSACTIONS_PANEL, this.handleOpen.bind(this));
        this.eventBus.unsubscribe(PendingTransactionsEventsEnum.CLOSE_PENDING_TRANSACTIONS, this.onClose.bind(this, { isUserClick: false }));
    }
    handleOpen() {
        this.isOpen = true;
    }
    handleClose() {
        this.isOpen = false;
        this.onClose({ isUserClick: true });
    }
    onClose(props = { isUserClick: true }) {
        this.isOpen = false;
        if (props.isUserClick) {
            this.eventBus.publish(PendingTransactionsEventsEnum.CLOSE_PENDING_TRANSACTIONS);
        }
    }
    dataUpdate(payload) {
        if (payload.shouldClose) {
            return this.onClose({ isUserClick: false });
        }
        this.isOpen = true;
        this.data = Object.assign({}, payload);
        forceUpdate(this);
    }
    async getEventBus() {
        return this.eventBus;
    }
    render() {
        return (h("mvx-side-panel", { key: 'fb6e2a2f21fb8105ee6d8b053ab89d4855f32285', isOpen: this.isOpen, panelClassName: "pending-transactions-panel", onClose: this.handleClose.bind(this) }, h("div", { key: '82b63e9f37a8c863dc7068dfe49a03aad098b9c6', class: "pending-transactions-content" }, h("div", { key: '20b36237d7fb57b8dfa991a7d9d2df236e9389e8', class: "pending-transactions-header" }, h("h2", { key: 'c9ba8e40186f3c4a369b413ffb2a9c7704bd2c78', "data-testid": DataTestIdsEnum.pendingTransactionsTitle }, this.data.title), h("h4", { key: 'a6a05721a1b77877e081b64c9a26822da0715012', "data-testid": DataTestIdsEnum.pendingTransactionsSubtitle }, this.data.subtitle)), h("div", { key: 'a1efef97c39172f741e05b55a08cccaf2755a418', class: "pending-transactions-body" }, h("button", { key: '9e4654746d024fd9b14fb23441365cf1f73d6970', class: "close-button", onClick: this.handleClose.bind(this) }, "Close")))));
    }
    static get is() { return "mvx-pending-transactions-panel"; }
    static get originalStyleUrls() {
        return {
            "$": ["pending-transactions-panel.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["pending-transactions-panel.css"]
        };
    }
    static get properties() {
        return {
            "data": {
                "type": "unknown",
                "attribute": "data",
                "mutable": false,
                "complexType": {
                    "original": "IPendingTransactionsPanelData",
                    "resolved": "IPendingTransactionsPanelData",
                    "references": {
                        "IPendingTransactionsPanelData": {
                            "location": "import",
                            "path": "./pending-transactions-panel.types",
                            "id": "src/components/functional/pending-transactions-panel/pending-transactions-panel.types.ts::IPendingTransactionsPanelData"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "defaultValue": "{\n    isPending: false,\n    title: '',\n    subtitle: '',\n  }"
            }
        };
    }
    static get states() {
        return {
            "isOpen": {}
        };
    }
    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": []
                }
            }
        };
    }
}
//# sourceMappingURL=pending-transactions-panel.js.map
