const core = require('@sentry/core');
const nodeNative = require('@sentry/node-native');
const electron = require('electron');

/**
 * > **Note**
 * >
 * > You should add `@sentry/node-native` to your dependencies to use this integration.
 *
 * Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.
 *
 * Uses a background worker and native module to detect when the main thread is blocked for longer than the configured
 * threshold (default: 1 second). When a block is detected, it captures an event with stack traces for every thread.
 *
 * ```js
 * import * as Sentry from '@sentry/electron/main';
 * import { eventLoopBlockIntegration } from '@sentry/electron/native';
 *
 * Sentry.init({
 *   dsn: '__YOUR_DSN__',
 *   integrations: [
 *     eventLoopBlockIntegration({
 *       threshold: 500, // Report blocks longer than 500ms
 *     }),
 *   ],
 * });
 * ```
 */
const eventLoopBlockIntegration = core.defineIntegration((options = {}) => {
    if (process.type === 'renderer') {
        throw new Error('Detected `eventLoopBlockIntegration` in renderer process. This integration should only be used in the Electron main process.');
    }
    const integration = nodeNative.eventLoopBlockIntegration({
        ...options,
        staticTags: {
            'event.environment': 'javascript',
            'event.origin': 'electron',
            'event.process': 'browser',
            ...options.staticTags,
        },
        appRootPath: electron.app.getAppPath(),
    });
    electron.powerMonitor.on('suspend', () => {
        integration.stop();
    });
    electron.powerMonitor.on('lock-screen', () => {
        integration.stop();
    });
    electron.powerMonitor.on('resume', () => {
        integration.start();
    });
    electron.powerMonitor.on('unlock-screen', () => {
        integration.start();
    });
    return integration;
});

exports.disableBlockDetectionForCallback = nodeNative.disableBlockDetectionForCallback;
exports.pauseEventLoopBlockDetection = nodeNative.pauseEventLoopBlockDetection;
exports.restartEventLoopBlockDetection = nodeNative.restartEventLoopBlockDetection;
exports.eventLoopBlockIntegration = eventLoopBlockIntegration;//# sourceMappingURL=http://go/sourcemap/sourcemaps/042b3c1a4c53f2c3808067f519fbfc67b72cad80/node_modules/@sentry/electron/native/event-loop-blocked-integration.js.map
