/**
 * Hook Events
 *
 * EventEmitter-based hook system for PreCompact, Notification, and PermissionRequest events.
 * Singleton pattern for global event coordination.
 */
import { EventEmitter } from 'events';
import { logger } from '../utils/logger.js';
// ============================================================================
// HookEventEmitter
// ============================================================================
export class HookEventEmitter extends EventEmitter {
    static instance = null;
    constructor() {
        super();
        logger.debug('HookEventEmitter initialized');
    }
    static getInstance() {
        if (!HookEventEmitter.instance) {
            HookEventEmitter.instance = new HookEventEmitter();
        }
        return HookEventEmitter.instance;
    }
    static resetInstance() {
        if (HookEventEmitter.instance) {
            HookEventEmitter.instance.removeAllListeners();
        }
        HookEventEmitter.instance = null;
    }
    emitPreCompact(context) {
        this.emit('PreCompact', context);
    }
    emitNotification(notification) {
        this.emit('Notification', notification);
    }
    emitPermissionRequest(request) {
        const listeners = this.listeners('PermissionRequest');
        if (listeners.length === 0) {
            return { action: 'ask' };
        }
        // Call the first listener synchronously and return its result
        const handler = listeners[0];
        return handler(request);
    }
    onPreCompact(handler) {
        this.on('PreCompact', handler);
    }
    onNotification(handler) {
        this.on('Notification', handler);
    }
    onPermissionRequest(handler) {
        this.on('PermissionRequest', handler);
    }
}
//# sourceMappingURL=hook-events.js.map