import { EMPTY_STREAM, stream } from "../utils/stream.js";
import { MultiMap } from "../utils/collections.js";
var StreamScope = class {
	constructor(e, r, i) {
		this.elements = e, this.outerScope = r, this.caseInsensitive = i?.caseInsensitive ?? !1, this.concatOuterScope = i?.concatOuterScope ?? !0;
	}
	getAllElements() {
		return this.outerScope ? this.elements.concat(this.outerScope.getAllElements()) : this.elements;
	}
	getElement(e) {
		let r = this.caseInsensitive ? e.toLowerCase() : e, i = this.caseInsensitive ? this.elements.find((e) => e.name.toLowerCase() === r) : this.elements.find((r) => r.name === e);
		if (i) return i;
		if (this.outerScope) return this.outerScope.getElement(e);
	}
	getElements(e) {
		let r = this.caseInsensitive ? e.toLowerCase() : e, i = this.caseInsensitive ? this.elements.filter((e) => e.name.toLowerCase() === r) : this.elements.filter((r) => r.name === e);
		return (this.concatOuterScope || i.isEmpty()) && this.outerScope ? i.concat(this.outerScope.getElements(e)) : i;
	}
}, MapScope = class {
	constructor(e, r, i) {
		this.elements = /* @__PURE__ */ new Map(), this.caseInsensitive = i?.caseInsensitive ?? !1, this.concatOuterScope = i?.concatOuterScope ?? !0;
		for (let r of e) {
			let e = this.caseInsensitive ? r.name.toLowerCase() : r.name;
			this.elements.set(e, r);
		}
		this.outerScope = r;
	}
	getElement(e) {
		let r = this.caseInsensitive ? e.toLowerCase() : e, i = this.elements.get(r);
		if (i) return i;
		if (this.outerScope) return this.outerScope.getElement(e);
	}
	getElements(e) {
		let i = this.caseInsensitive ? e.toLowerCase() : e, a = this.elements.get(i), o = a ? [a] : [];
		return (this.concatOuterScope || o.length > 0) && this.outerScope ? stream(o).concat(this.outerScope.getElements(e)) : stream(o);
	}
	getAllElements() {
		let e = stream(this.elements.values());
		return this.outerScope && (e = e.concat(this.outerScope.getAllElements())), e;
	}
}, MultiMapScope = class {
	constructor(e, r, a) {
		this.elements = new MultiMap(), this.caseInsensitive = a?.caseInsensitive ?? !1, this.concatOuterScope = a?.concatOuterScope ?? !0;
		for (let r of e) {
			let e = this.caseInsensitive ? r.name.toLowerCase() : r.name;
			this.elements.add(e, r);
		}
		this.outerScope = r;
	}
	getElement(e) {
		let r = this.caseInsensitive ? e.toLowerCase() : e, i = this.elements.get(r)[0];
		if (i) return i;
		if (this.outerScope) return this.outerScope.getElement(e);
	}
	getElements(e) {
		let i = this.caseInsensitive ? e.toLowerCase() : e, a = this.elements.get(i);
		return (this.concatOuterScope || a.length === 0) && this.outerScope ? stream(a).concat(this.outerScope.getElements(e)) : stream(a);
	}
	getAllElements() {
		let e = stream(this.elements.values());
		return this.outerScope && (e = e.concat(this.outerScope.getAllElements())), e;
	}
};
const EMPTY_SCOPE = {
	getElement() {},
	getElements() {
		return EMPTY_STREAM;
	},
	getAllElements() {
		return EMPTY_STREAM;
	}
};
export { EMPTY_SCOPE, MapScope, MultiMapScope, StreamScope };
