import { t as e } from "../../utils-B7XIe3qq.js";
import * as t from "react";
import { jsx as n, jsxs as r } from "react/jsx-runtime";
//#region src/react/primitives/file-tree.tsx
function i({ className: t }) {
	return /* @__PURE__ */ n("svg", {
		viewBox: "0 0 16 16",
		fill: "none",
		className: e("size-3.5", t),
		children: /* @__PURE__ */ n("path", {
			d: "M6 4l4 4-4 4",
			stroke: "currentColor",
			strokeWidth: "1.5",
			strokeLinecap: "round",
			strokeLinejoin: "round"
		})
	});
}
function a() {
	return /* @__PURE__ */ n("svg", {
		viewBox: "0 0 16 16",
		fill: "none",
		className: "size-4",
		children: /* @__PURE__ */ n("path", {
			d: "M1.5 2.5h4.25l1.25 1.5h7.5v9.5h-13z",
			stroke: "currentColor",
			strokeWidth: "1.2",
			strokeLinejoin: "round"
		})
	});
}
function o() {
	return /* @__PURE__ */ r("svg", {
		viewBox: "0 0 16 16",
		fill: "none",
		className: "size-4",
		children: [/* @__PURE__ */ n("path", {
			d: "M1.5 2.5h4.25l1.25 1.5h7.5v2H3.5l-2 6.5z",
			stroke: "currentColor",
			strokeWidth: "1.2",
			strokeLinejoin: "round"
		}), /* @__PURE__ */ n("path", {
			d: "M3.5 6.5h11l-2 7h-11z",
			stroke: "currentColor",
			strokeWidth: "1.2",
			strokeLinejoin: "round"
		})]
	});
}
function s() {
	return /* @__PURE__ */ r("svg", {
		viewBox: "0 0 16 16",
		fill: "none",
		className: "size-4",
		children: [/* @__PURE__ */ n("path", {
			d: "M3 1.5h6.5L13 5v9.5H3z",
			stroke: "currentColor",
			strokeWidth: "1.2",
			strokeLinejoin: "round"
		}), /* @__PURE__ */ n("path", {
			d: "M9.5 1.5v3.5H13",
			stroke: "currentColor",
			strokeWidth: "1.2",
			strokeLinejoin: "round"
		})]
	});
}
function c({ node: t, depth: l, indent: u, showIcons: d, selectable: f, multiSelect: p, isDraggable: m, selectedIds: h, expandedIds: g, onToggle: _, onSelectNode: v, onDrop: y }) {
	let b = t.type === "folder", x = g.has(t.id), S = h.has(t.id), C = (e) => {
		b && _(t), f && v(t, p && (e.ctrlKey || e.metaKey));
	}, w = (e) => {
		e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", t.id), e.dataTransfer.setData("application/json", JSON.stringify(t));
	}, T = (e) => {
		b && (e.preventDefault(), e.dataTransfer.dropEffect = "move");
	}, E = (e) => {
		if (e.preventDefault(), b && y) try {
			let n = e.dataTransfer.getData("application/json"), r = JSON.parse(n);
			r.id !== t.id && y(r, t);
		} catch {}
	};
	return /* @__PURE__ */ r("li", {
		role: "treeitem",
		"aria-expanded": b ? x : void 0,
		children: [/* @__PURE__ */ r("div", {
			className: e("flex cursor-pointer items-center gap-1.5 rounded-md px-2 py-1 text-sm transition-colors", "hover:bg-surface-secondary", S && "bg-surface-secondary text-foreground", !S && "text-foreground-secondary"),
			style: { paddingLeft: `${l * u + 8}px` },
			onClick: C,
			draggable: m,
			onDragStart: m ? w : void 0,
			onDragOver: m ? T : void 0,
			onDrop: m ? E : void 0,
			children: [
				/* @__PURE__ */ n("span", {
					className: e("shrink-0", !b && "invisible"),
					children: /* @__PURE__ */ n(i, { className: e("transition-transform duration-150", x && "rotate-90") })
				}),
				d && /* @__PURE__ */ n("span", {
					className: "text-foreground-secondary shrink-0",
					children: t.icon ? t.icon : n(b ? x ? o : a : s, {})
				}),
				/* @__PURE__ */ n("span", {
					className: "truncate",
					children: t.name
				})
			]
		}), b && x && t.children && t.children.length > 0 && /* @__PURE__ */ n("ul", {
			role: "group",
			children: t.children.map((e) => /* @__PURE__ */ n(c, {
				node: e,
				depth: l + 1,
				indent: u,
				showIcons: d,
				selectable: f,
				multiSelect: p,
				isDraggable: m,
				selectedIds: h,
				expandedIds: g,
				onToggle: _,
				onSelectNode: v,
				onDrop: y
			}, e.id))
		})]
	});
}
function l(e, t) {
	for (let n of e) n.type === "folder" && n.expanded && t.add(n.id), n.children && l(n.children, t);
}
function u(e, t) {
	for (let n of e) n.selected && t.add(n.id), n.children && u(n.children, t);
}
function d({ data: r, selectable: i = !0, multiSelect: a = !1, draggable: o = !1, showIcons: s = !0, indent: d = 16, onSelect: f, onExpand: p, onDrop: m, className: h, ...g }) {
	let [_, v] = t.useState(() => {
		let e = /* @__PURE__ */ new Set();
		return l(r, e), e;
	}), [y, b] = t.useState(() => {
		let e = /* @__PURE__ */ new Set();
		return u(r, e), e;
	}), x = t.useCallback((e) => {
		v((t) => {
			let n = new Set(t);
			return n.has(e.id) ? n.delete(e.id) : n.add(e.id), n;
		}), p?.(e);
	}, [p]), S = t.useCallback((e, t) => {
		b((n) => {
			if (t) {
				let t = new Set(n);
				return t.has(e.id) ? t.delete(e.id) : t.add(e.id), t;
			}
			return new Set([e.id]);
		}), f?.(e);
	}, [f]);
	return /* @__PURE__ */ n("div", {
		"data-slot": "file-tree",
		className: e("bg-glass border-border-glass rounded-lg border backdrop-blur-[20px]", h),
		...g,
		children: r.length === 0 ? /* @__PURE__ */ n("div", {
			className: "text-foreground-secondary p-4 text-center text-sm",
			children: "No files"
		}) : /* @__PURE__ */ n("ul", {
			role: "tree",
			className: "p-1",
			children: r.map((e) => /* @__PURE__ */ n(c, {
				node: e,
				depth: 0,
				indent: d,
				showIcons: s,
				selectable: i,
				multiSelect: a,
				isDraggable: o,
				selectedIds: y,
				expandedIds: _,
				onToggle: x,
				onSelectNode: S,
				onDrop: m
			}, e.id))
		})
	});
}
d.displayName = "FileTree";
//#endregion
export { d as FileTree };

//# sourceMappingURL=file-tree.js.map