import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";
import { h } from "@stencil/core";
import { EventBus } from "../../../utils/EventBus";
import { NotificationsFeedEventsEnum } from "./notifications-feed.types";
export class NotificationsFeed {
    constructor() {
        this.isOpen = false;
        this.pendingTransactions = [];
        this.transactionsHistory = [];
        this.eventBus = new EventBus();
        this.closeEventTimeout = null;
        this.handleClose = () => {
            this.isOpen = false;
            this.eventBus.publish(NotificationsFeedEventsEnum.CLOSE_NOTIFICATIONS_FEED);
        };
        this.handleClear = () => {
            this.eventBus.publish(NotificationsFeedEventsEnum.CLEAR_NOTIFICATIONS_FEED_HISTORY);
        };
        this.handleViewAll = () => {
            this.isOpen = true;
        };
    }
    clearTimeouts() {
        if (this.closeEventTimeout) {
            clearTimeout(this.closeEventTimeout);
            this.closeEventTimeout = null;
        }
    }
    disconnectedCallback() {
        this.clearTimeouts();
        this.eventBus.unsubscribe(NotificationsFeedEventsEnum.PENDING_TRANSACTIONS_UPDATE, this.pendingTransactionsUpdate.bind(this));
        this.eventBus.unsubscribe(NotificationsFeedEventsEnum.TRANSACTIONS_HISTORY_UPDATE, this.transactionsHistoryUpdate.bind(this));
        this.eventBus.unsubscribe(NotificationsFeedEventsEnum.OPEN_NOTIFICATIONS_FEED, this.handleViewAll.bind(this));
    }
    async getEventBus() {
        return this.eventBus;
    }
    render() {
        var _a, _b, _c;
        const hasActivity = ((_a = this.transactionsHistory) === null || _a === void 0 ? void 0 : _a.length) > 0;
        const hasPending = ((_b = this.pendingTransactions) === null || _b === void 0 ? void 0 : _b.length) > 0;
        return (h("mvx-side-panel", { key: '783de8330d5949640a01ca72ac4fe2cac3aba229', isOpen: this.isOpen, panelTitle: "Notifications Feed", onClose: this.handleClose }, h("div", { key: '935ab5ad191c5e6d82377488c8f4f29630efac2d', class: "feed-content" }, h("div", { key: '1606428b4cd7780f2d1a81282e45c85d7d662c5a', class: "notifications-info" }, h("mvx-fa-icon", { key: '658919ecda9ed8ff3b85d6bac6ce10a5b172056e', class: "info-icon", icon: faInfoCircle }), "This feed is stored in your browser and will be reset when a new session is started.", h("fa-icon", { key: '22b2f9859621f9ff86cdcbb3887a4df27192ff24', class: "info-icon", icon: faInfoCircle })), hasPending && (h("div", { key: '6154d0424c2d65893ae1f9a43faf8e513e474f0b', class: "notifications-container" }, h("div", { key: '5307c87b0eafc7b7e01c6e3b83f8c23dd5339416', class: "processing-status" }, "Processing..."), (_c = this.pendingTransactions) === null || _c === void 0 ? void 0 :
            _c.map(toast => h("mvx-transaction-toast", Object.assign({ fullWidth: true }, toast))))), h("div", { key: '03e74818a2c940c32fd712bc89f21ab6a5ba73af', class: "activity-section" }, h("div", { key: '73bc9330eafcc8d98ee50c5503bbf58f4dc53fb2', class: "activity-header" }, h("h3", { key: '0f7736798d0b04ae05ec75e3f2b94f1f6b62b684', class: "activity-title" }, "Activity"), hasActivity && (h("button", { key: 'e2271bdce835c9c54f3ac21e1166d23acd00d312', class: "clear-button", onClick: this.handleClear }, "Clear"))), h("div", { key: 'bb1ec5a3a18e55c0102561a14778ac1a22b4a85a', class: "activity-list" }, hasActivity ? (this.transactionsHistory.map(transaction => h("mvx-transaction-list-item", { transaction: transaction }))) : (h("div", { class: "no-activity" }, "No activity to show")))))));
    }
    pendingTransactionsUpdate(payload) {
        this.pendingTransactions = [...payload];
    }
    transactionsHistoryUpdate(payload) {
        this.transactionsHistory = [...payload];
    }
    componentDidLoad() {
        this.eventBus.subscribe(NotificationsFeedEventsEnum.PENDING_TRANSACTIONS_UPDATE, this.pendingTransactionsUpdate.bind(this));
        this.eventBus.subscribe(NotificationsFeedEventsEnum.TRANSACTIONS_HISTORY_UPDATE, this.transactionsHistoryUpdate.bind(this));
        this.eventBus.subscribe(NotificationsFeedEventsEnum.OPEN_NOTIFICATIONS_FEED, this.handleViewAll.bind(this));
    }
    static get is() { return "mvx-notifications-feed"; }
    static get originalStyleUrls() {
        return {
            "$": ["notifications-feed.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["notifications-feed.css"]
        };
    }
    static get states() {
        return {
            "isOpen": {},
            "pendingTransactions": {},
            "transactionsHistory": {}
        };
    }
    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=notifications-feed.js.map
