import { r as registerInstance, c as createEvent, g as getElement } from './index-77a9c9e7.js';
import { g as eN } from './index.esm.min-db2d29e8.js';
import { o as ot } from './index.esm.min-9889e78b.js';
import { s as store } from './redux-store.service-dc54f48e.js';

const SDK_ERRORS = [new ot().name];
const BpSdkErrorEventContainer = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.sdkError = 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 = store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                isDebug: 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 getElement(this); }
};

export { BpSdkErrorEventContainer as bp_sdk_error_event_container };
