import { useFilterNamespaces } from "./useNamespaces.js";
import { c } from "react/compiler-runtime";
import { useMemo } from "react";
function buildNamespaceTree(e) {
	let t = /* @__PURE__ */ new Map();
	e.forEach((e) => {
		t.set(e.id, {
			...e,
			childNodes: []
		});
	});
	let n = [];
	return e.forEach((e) => {
		let r = t.get(e.id);
		if (e.parentId) {
			let i = t.get(e.parentId);
			i ? i.childNodes.push(r) : (console.warn(`Parent namespace with ID ${e.parentId} not found for ${e.id}`), n.push(r));
		} else n.push(r);
	}), n;
}
function useNamespaceTree(n) {
	let i = c(4), a = useFilterNamespaces(n), o;
	i[0] === a.data ? o = i[1] : (o = a.data ?? [], i[0] = a.data, i[1] = o);
	let s = o, l;
	return i[2] === s ? l = i[3] : (l = s.length ? buildNamespaceTree(s) : [], i[2] = s, i[3] = l), l;
}
export { useNamespaceTree };
