/**
 * FilteredEventEmitter - A view of an event emitter that only passes events matching a filter
 *
 * Created via TypedEventEmitter.filter() to provide a scoped view of events.
 */
/**
 * FilteredEventEmitter - A view of an event emitter that only passes events matching a filter
 */
export class FilteredEventEmitter {
    source;
    type;
    predicate;
    listenerIds = [];
    constructor(source, type, predicate) {
        this.source = source;
        this.type = type;
        this.predicate = predicate;
    }
    /**
     * Add a listener that only receives filtered events
     */
    on(listener, options = {}) {
        const id = this.source.on(this.type, listener, {
            ...options,
            filter: this.predicate,
        });
        this.listenerIds.push(id);
        return id;
    }
    /**
     * Add a one-time listener that only receives filtered events
     */
    once(listener, options = {}) {
        const id = this.source.once(this.type, listener, {
            ...options,
            filter: this.predicate,
        });
        this.listenerIds.push(id);
        return id;
    }
    /**
     * Remove a specific listener
     */
    off(listenerId) {
        const index = this.listenerIds.indexOf(listenerId);
        if (index !== -1) {
            this.listenerIds.splice(index, 1);
        }
        return this.source.off(listenerId);
    }
    /**
     * Remove all listeners created through this filtered emitter
     */
    offAll() {
        for (const id of this.listenerIds) {
            this.source.off(id);
        }
        this.listenerIds = [];
    }
    /**
     * Wait for a filtered event
     */
    waitFor(options = {}) {
        return this.source.waitFor(this.type, {
            ...options,
            filter: this.predicate,
        });
    }
}
//# sourceMappingURL=filtered-emitter.js.map