import { forceUpdate, h } from "@stencil/core";
import { EventBus } from "../../../utils/EventBus";
import { ToastEventsEnum } from "./toast-list.types";
export class ToastList {
    constructor() {
        this.eventBus = new EventBus();
    }
    async getEventBus() {
        return this.eventBus;
    }
    disconnectedCallback() {
        this.eventBus.unsubscribe(ToastEventsEnum.TRANSACTION_TOAST_DATA_UPDATE, this.transactionToastUpdate.bind(this));
        this.eventBus.unsubscribe(ToastEventsEnum.CUSTOM_TOAST_DATA_UPDATE, this.customToastsUpdate.bind(this));
    }
    handleCustomToastDelete(toastId) {
        this.eventBus.publish(ToastEventsEnum.CLOSE_TOAST, toastId);
    }
    handleTransactionToastDelete(toastId) {
        this.eventBus.publish(ToastEventsEnum.CLOSE_TOAST, toastId);
    }
    handleViewAllClick() {
        this.eventBus.publish(ToastEventsEnum.OPEN_NOTIFICATIONS_FEED);
    }
    render() {
        var _a, _b, _c;
        const hasTransactionToasts = ((_a = this.transactionToasts) === null || _a === void 0 ? void 0 : _a.length) > 0;
        return (h("div", { key: 'edc436072161689938deb40599be8bd34997592b', class: {
                'toast-list': true,
                'toast-list-bottom': hasTransactionToasts,
            }, id: "toast-list" }, (_b = this.customToasts) === null || _b === void 0 ? void 0 :
            _b.map(toast => h("mvx-generic-toast", { toast: toast, onDeleteToast: this.handleCustomToastDelete.bind(this, toast.toastId) })), (_c = this.transactionToasts) === null || _c === void 0 ? void 0 :
            _c.map(toast => (h("mvx-transaction-toast", Object.assign({}, toast, { onDeleteToast: this.handleTransactionToastDelete.bind(this, toast.toastId) })))), hasTransactionToasts && (h("div", { key: 'b4fbf199402480ecbb8fd6166a5ff88a785c1783', class: "view-all-button-container" }, h("button", { key: 'b73761b4c5e0a296ad0bc0aed8a24730bbe8e691', class: "view-all-button", onClick: this.handleViewAllClick.bind(this) }, "View All")))));
    }
    transactionToastUpdate(payload) {
        this.transactionToasts = [...payload];
        forceUpdate(this);
    }
    customToastsUpdate(payload) {
        this.customToasts = [...payload];
        forceUpdate(this);
    }
    componentDidLoad() {
        this.eventBus.subscribe(ToastEventsEnum.TRANSACTION_TOAST_DATA_UPDATE, this.transactionToastUpdate.bind(this));
        this.eventBus.subscribe(ToastEventsEnum.CUSTOM_TOAST_DATA_UPDATE, this.customToastsUpdate.bind(this));
    }
    static get is() { return "mvx-toast-list"; }
    static get originalStyleUrls() {
        return {
            "$": ["toast-list.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["toast-list.css"]
        };
    }
    static get properties() {
        return {
            "transactionToasts": {
                "type": "unknown",
                "attribute": "transaction-toasts",
                "mutable": false,
                "complexType": {
                    "original": "ITransactionToast[]",
                    "resolved": "ITransactionToast[]",
                    "references": {
                        "ITransactionToast": {
                            "location": "import",
                            "path": "./components/transaction-toast/transaction-toast.type",
                            "id": "src/components/functional/toasts-list/components/transaction-toast/transaction-toast.type.ts::ITransactionToast"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "customToasts": {
                "type": "unknown",
                "attribute": "custom-toasts",
                "mutable": false,
                "complexType": {
                    "original": "CustomToastType[]",
                    "resolved": "CustomToastType[]",
                    "references": {
                        "CustomToastType": {
                            "location": "import",
                            "path": "./components/transaction-toast/transaction-toast.type",
                            "id": "src/components/functional/toasts-list/components/transaction-toast/transaction-toast.type.ts::CustomToastType"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            }
        };
    }
    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=toast-list.js.map
