import { createElement as e, useMemo as t } from "react";
import { cn as n, handleKeyboardActivation as r } from "@ryuzaki13/react-foundation-lib/utils";
import { jsx as i, jsxs as a } from "react/jsx-runtime";
var o = {
	nodeItem: "yJlLGL",
	treeContainer: "lWEMr2",
	nestedList: "WfVcwm",
	nestedСounter: "_27DQ-H"
}, s = "children";
function c(e, t) {
	return e.id ?? e.key ?? t;
}
function l({ node: e, level: t }) {
	let n = e.title ?? e.text ?? e.label;
	return typeof n == "string" || typeof n == "number" ? /* @__PURE__ */ i("div", {
		"aria-level": t + 1,
		style: { display: "inline-block" },
		children: n
	}) : /* @__PURE__ */ i("div", {
		"aria-level": t + 1,
		children: JSON.stringify(n ?? e)
	});
}
function u(u) {
	let { data: d, childrenKey: f = s, getChildren: p, getKey: m = c, renderNode: h, onNodeClick: g, containerElement: _ = "ol", containerClassName: v, containerStyle: y, nestedCounter: b, itemClassName: x, itemStyle: S, nestedListClassName: C, nestedListStyle: w, labelClassName: T, labelStyle: E } = u, D = (e) => {
		if (typeof p == "function") return p(e);
		let t = e[f];
		return Array.isArray(t) ? t : void 0;
	}, O = (t, s, c, u) => {
		let d = D(t), f = Array.isArray(d) && d.length > 0, p = !f, v = typeof h == "function" ? h({
			node: t,
			level: c,
			hasChildren: f,
			isLeaf: p,
			path: u
		}) : l({
			node: t,
			level: c,
			hasChildren: f,
			isLeaf: p,
			path: u
		});
		function y() {
			let e = /* @__PURE__ */ i("div", {
				className: T,
				style: E,
				"aria-current": p ? void 0 : !1,
				children: v
			});
			return g ? /* @__PURE__ */ i("button", {
				type: "button",
				onClick: () => g(t, u),
				onKeyDown: (e) => {
					r(e, () => g(t, u));
				},
				"data-ui": "tree-node-button",
				"data-action": "select-tree-node",
				"aria-expanded": f ? !0 : void 0,
				style: {
					background: "transparent",
					border: 0,
					padding: 0,
					cursor: "pointer"
				},
				children: e
			}) : /* @__PURE__ */ i("div", {
				role: "presentation",
				children: e
			});
		}
		return /* @__PURE__ */ a("li", {
			className: n(o.nodeItem, x),
			style: S,
			children: [/* @__PURE__ */ i(y, {}), f && e(_, {
				className: C ?? o.nestedList,
				style: w
			}, d.map((e, t) => O(e, t, c + 1, [...u, t])))]
		}, m(t, s, u));
	}, k = t(() => d.map((e, t) => O(e, t, 0, [t])), [
		d,
		f,
		p,
		m,
		h,
		g,
		_,
		x,
		S,
		C,
		w,
		T,
		E
	]);
	return e(_, {
		className: n(v ?? o.treeContainer, b && o.nestedСounter),
		style: y
	}, k);
}
//#endregion
export { u as Tree };

//# sourceMappingURL=index.js.map