import { removeNotification } from "@boldpenguin/sdk-redux";
import { h } from "@stencil/core";
import store from "../../services/redux-store.service";
export class BpSdkNotificationsContainer {
    constructor() {
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            store.mapDispatchToProps(this, {
                removeNotification,
            });
            this.storeUnsubscribe = store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                notifications: state.notifications,
            };
        };
        this.handleRemoveNotification = (notification) => {
            this.removeNotification(notification);
        };
        this.notifications = undefined;
        this.useExternal = false;
    }
    resetState() {
        this.notifications = [];
    }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-notifications-container');
        customElements.whenDefined('bp-sdk-external-notifications-container').then(() => {
            this.useExternal = true;
        });
        this.handleSubscriptions();
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return h("bp-sdk-external-notifications-container", { notifications: this.notifications });
    }
    renderInternal() {
        if (this.notifications.length > 0) {
            return (h("div", { class: "bp-sdk-notifications-container__container" }, this.notifications.map((notification) => this.renderNotifications(notification))));
        }
    }
    renderNotifications(notification) {
        return h("bp-sdk-notification", { notification: notification, removeNotification: this.handleRemoveNotification });
    }
    static get is() { return "bp-sdk-notifications-container"; }
    static get originalStyleUrls() {
        return {
            "$": ["./bp-sdk-notifications-container.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bp-sdk-notifications-container.css"]
        };
    }
    static get properties() {
        return {
            "notifications": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "INotificationState[]",
                    "resolved": "INotificationState[]",
                    "references": {
                        "INotificationState": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::INotificationState"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                }
            }
        };
    }
    static get states() {
        return {
            "useExternal": {}
        };
    }
}
