class EventBus {
    handlers = new Map();
    allHandlers = [];
    /**
     * Subscribe to specific tag
     */
    subscribe(tag, handler) {
        if (!this.handlers.has(tag)) {
            this.handlers.set(tag, []);
        }
        this.handlers.get(tag).push(handler);
        // Return unsubscribe function
        return () => {
            const handlers = this.handlers.get(tag);
            if (handlers) {
                const index = handlers.indexOf(handler);
                if (index > -1) {
                    handlers.splice(index, 1);
                }
            }
        };
    }
    /**
     * Subscribe to all events
     */
    subscribeAll(handler) {
        this.allHandlers.push(handler);
        return () => {
            const index = this.allHandlers.indexOf(handler);
            if (index > -1) {
                this.allHandlers.splice(index, 1);
            }
        };
    }
    /**
     * Emit event
     */
    emit(tag, message) {
        const event = {
            timestamp: Date.now(),
            tag,
            message,
        };
        // Notify tag-specific handlers
        const tagHandlers = this.handlers.get(tag) || [];
        tagHandlers.forEach((handler) => handler(event));
        // Notify all handlers
        this.allHandlers.forEach((handler) => handler(event));
    }
}
export const eventBus = new EventBus();
//# sourceMappingURL=eventBus.js.map