import { r as registerInstance, h, g as getElement } from './index-77a9c9e7.js';
import { T as TN } from './index.esm.min-db2d29e8.js';
import { s as store } from './redux-store.service-dc54f48e.js';

const BpSdkMessageContainer = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            this.storeUnsubscribe = store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                messages: 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 h("bp-sdk-external-message-container", { messages: this.messages });
    }
    renderInternal() {
        return this.lastMessage && h("bp-sdk-message", { message: this.lastMessage });
    }
    get el() { return getElement(this); }
    static get watchers() { return {
        "messages": ["handleMessagesUpdate"]
    }; }
};

export { BpSdkMessageContainer as bp_sdk_message_container };
