import { URI as e, Utils as t } from "../../../vscode-uri/lib/esm/index.js";
//#region ../../node_modules/langium/lib/utils/uri-utils.js
var n;
(function(n) {
	n.basename = t.basename, n.dirname = t.dirname, n.extname = t.extname, n.joinPath = t.joinPath, n.resolvePath = t.resolvePath;
	let r = typeof process == "object" && process?.platform === "win32";
	function i(e, t) {
		return e?.toString() === t?.toString();
	}
	n.equals = i;
	function a(t, n) {
		let i = typeof t == "string" ? e.parse(t).path : t.path, a = typeof n == "string" ? e.parse(n).path : n.path, o = i.split("/").filter((e) => e.length > 0), s = a.split("/").filter((e) => e.length > 0);
		if (r) {
			let e = /^[A-Z]:$/;
			if (o[0] && e.test(o[0]) && (o[0] = o[0].toLowerCase()), s[0] && e.test(s[0]) && (s[0] = s[0].toLowerCase()), o[0] !== s[0]) return a.substring(1);
		}
		let c = 0;
		for (; c < o.length && o[c] === s[c]; c++);
		return "../".repeat(o.length - c) + s.slice(c).join("/");
	}
	n.relative = a;
	function o(t) {
		return e.parse(t.toString()).toString();
	}
	n.normalize = o;
	function s(e, t) {
		let n = typeof e == "string" ? e : e.path, r = typeof t == "string" ? t : t.path;
		return r.charAt(r.length - 1) === "/" && (r = r.slice(0, -1)), n.charAt(n.length - 1) === "/" && (n = n.slice(0, -1)), r === n ? !0 : r.length < n.length || r.charAt(n.length) !== "/" ? !1 : r.startsWith(n);
	}
	n.contains = s;
})(n ||= {});
var r = class {
	constructor() {
		this.root = {
			name: "",
			children: /* @__PURE__ */ new Map()
		};
	}
	normalizeUri(e) {
		return n.normalize(e);
	}
	clear() {
		this.root.children.clear();
	}
	insert(e, t) {
		let n = this.getNode(this.normalizeUri(e), !0);
		n.element = t;
	}
	delete(e) {
		let t = this.getNode(this.normalizeUri(e), !1);
		t?.parent && t.parent.children.delete(t.name);
	}
	has(e) {
		return this.getNode(this.normalizeUri(e), !1)?.element !== void 0;
	}
	hasNode(e) {
		return this.getNode(this.normalizeUri(e), !1) !== void 0;
	}
	find(e) {
		return this.getNode(this.normalizeUri(e), !1)?.element;
	}
	findNode(t) {
		let r = this.normalizeUri(t), i = this.getNode(r, !1);
		if (i) return {
			name: i.name,
			uri: n.joinPath(e.parse(r), i.name).toString(),
			element: i.element
		};
	}
	findChildren(t) {
		let r = this.normalizeUri(t), i = this.getNode(r, !1);
		return i ? Array.from(i.children.values()).map((t) => ({
			name: t.name,
			uri: n.joinPath(e.parse(r), t.name).toString(),
			element: t.element
		})) : [];
	}
	all() {
		return this.collectValues(this.root);
	}
	findAll(e) {
		let t = this.getNode(n.normalize(e), !1);
		return t ? this.collectValues(t) : [];
	}
	getNode(e, t) {
		let n = e.split("/");
		e.charAt(e.length - 1) === "/" && n.pop();
		let r = this.root;
		for (let e of n) {
			let n = r.children.get(e);
			if (!n) if (t) n = {
				name: e,
				children: /* @__PURE__ */ new Map(),
				parent: r
			}, r.children.set(e, n);
			else return;
			r = n;
		}
		return r;
	}
	collectValues(e) {
		let t = [];
		e.element && t.push(e.element);
		for (let n of e.children.values()) t.push(...this.collectValues(n));
		return t;
	}
};
//#endregion
export { r as UriTrie, n as UriUtils };
