'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-ceff47a0.js');
const index_esm_min = require('./index.esm.min-f57d151c.js');
const reduxStore_service = require('./redux-store.service-10b7725a.js');

const bpSdkNotificationsContainerCss = "";
const BpSdkNotificationsContainerStyle0 = bpSdkNotificationsContainerCss;

const BpSdkNotificationsContainer = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            reduxStore_service.store.mapDispatchToProps(this, {
                removeNotification: index_esm_min.bM,
            });
            this.storeUnsubscribe = reduxStore_service.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 index.h("bp-sdk-external-notifications-container", { notifications: this.notifications });
    }
    renderInternal() {
        if (this.notifications.length > 0) {
            return (index.h("div", { class: "bp-sdk-notifications-container__container" }, this.notifications.map((notification) => this.renderNotifications(notification))));
        }
    }
    renderNotifications(notification) {
        return index.h("bp-sdk-notification", { notification: notification, removeNotification: this.handleRemoveNotification });
    }
};
BpSdkNotificationsContainer.style = BpSdkNotificationsContainerStyle0;

exports.bp_sdk_notifications_container = BpSdkNotificationsContainer;
