import { __read } from "tslib";
import { JsErrorMonitor } from '../../monitors/js-error';
import { applyMonitor } from '../../utils';
import { getPluginConfig } from './utils';
export { JS_ERROR_EV_TYPE } from '../../monitors/js-error';
export { normalizeUnknownError } from '../../monitors/js-error/util';
export var JS_ERROR_MONITOR_PLUGIN_NAME = 'jsError';
var defaultConfig = {
    ignoreErrors: [],
    onerror: true,
    onunhandledrejection: true,
    captureGlobalAsync: false,
    dedupe: true,
};
export function JsErrorMonitorPlugin(client) {
    client.on('init', function () {
        // stop precollect listener no matter what is configured
        window.removeEventListener('error', client.pcErr, true);
        window.removeEventListener('unhandledrejection', client.pcRej, true);
        var config = getPluginConfig(client, JS_ERROR_MONITOR_PLUGIN_NAME, defaultConfig);
        if (!config) {
            return;
        }
        var _a = __read(applyMonitor(JsErrorMonitor, config, function (ev) {
            if (client.getBreadcrumbs) {
                ev.payload.breadcrumbs = client.getBreadcrumbs();
            }
            client.report(ev);
        }), 2), ReportJsError = _a[0], tearDown = _a[1];
        client.on('beforeDestroy', tearDown);
        client.provide('captureException', ReportJsError);
    });
}
//# sourceMappingURL=js-error.js.map