var __defProp = Object.defineProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, {
      get: all[name],
      enumerable: true,
      configurable: true,
      set: (newValue) => all[name] = () => newValue
    });
};
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);

// src/events.ts
class TypedEventEmitter {
  eventBus = new Map;
  emit(event, payload) {
    const handlers = this.eventBus.get(event);
    if (!handlers || handlers.size === 0) {
      return;
    }
    handlers.forEach((handler) => {
      try {
        handler(payload);
      } catch (error) {
        console.error(`Error in event handler for "${String(event)}":`, error);
      }
    });
  }
  on(event, handler) {
    if (!this.eventBus.has(event)) {
      this.eventBus.set(event, new Set);
    }
    const handlers = this.eventBus.get(event);
    handlers.add(handler);
    return () => {
      handlers.delete(handler);
      if (handlers.size === 0) {
        this.eventBus.delete(event);
      }
    };
  }
  once(event, handler) {
    const wrappedHandler = (payload) => {
      handler(payload);
      unsubscribe();
    };
    const unsubscribe = this.on(event, wrappedHandler);
    return unsubscribe;
  }
  off(event, handler) {
    const handlers = this.eventBus.get(event);
    if (handlers) {
      handlers.delete(handler);
      if (handlers.size === 0) {
        this.eventBus.delete(event);
      }
    }
  }
  removeAllListeners(event) {
    this.eventBus.delete(event);
  }
  clearAll() {
    this.eventBus.clear();
  }
  listenerCount(event) {
    return this.eventBus.get(event)?.size ?? 0;
  }
  eventNames() {
    return Array.from(this.eventBus.keys());
  }
}
function createEventEmitter() {
  return new TypedEventEmitter;
}
export {
  createEventEmitter,
  TypedEventEmitter
};

//# debugId=FE4625A85F9803BF64756E2164756E21
