'use strict';

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

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

const SDK_ERRORS = [new index_esm_min.ot().name];
const BpSdkErrorEventContainer = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.sdkError = index.createEvent(this, "sdkError", 7);
        this.handleError = (ev) => {
            try {
                const { error } = ev;
                if (SDK_ERRORS.includes(error === null || error === void 0 ? void 0 : error.name)) {
                    // Emit DOM event
                    this.sdkError.emit({ error });
                    // Send error to console if debug flag is on
                    this.isDebug && console.error(error);
                    // Send to error handler function if it's provided
                    this.errorHandler && this.errorHandler(error);
                }
            }
            catch (e) {
                // Swallow errors here, if we can't capture the error successfully just do nothing
            }
        };
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            this.storeUnsubscribe = reduxStore_service.store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                isDebug: index_esm_min$1.eN(state),
            };
        };
        this.errorHandler = undefined;
        this.isDebug = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    componentWillLoad() {
        window.addEventListener('error', this.handleError);
        this.handleSubscriptions();
    }
    disconnectedCallback() {
        this.storeUnsubscribe && this.storeUnsubscribe();
    }
    render() {
        return null;
    }
    get el() { return index.getElement(this); }
};

exports.bp_sdk_error_event_container = BpSdkErrorEventContainer;
