'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 BpSdkMessageContainer = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            this.storeUnsubscribe = reduxStore_service.store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                messages: index_esm_min.TN(state),
            };
        };
        this.messages = undefined;
        this.useExternal = false;
        this.lastMessage = undefined;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-message-container');
        customElements.whenDefined('bp-sdk-external-message-container').then(() => {
            this.useExternal = true;
        });
        this.handleSubscriptions();
    }
    handleMessagesUpdate(messages) {
        this.lastMessage = messages[this.messages.length - 1];
    }
    disconnectedCallback() {
        this.storeUnsubscribe && this.storeUnsubscribe();
    }
    componentWillUpdate() {
        this.handleSubscriptions();
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return index.h("bp-sdk-external-message-container", { messages: this.messages });
    }
    renderInternal() {
        return this.lastMessage && index.h("bp-sdk-message", { message: this.lastMessage });
    }
    get el() { return index.getElement(this); }
    static get watchers() { return {
        "messages": ["handleMessagesUpdate"]
    }; }
};

exports.bp_sdk_message_container = BpSdkMessageContainer;
