import { cn } from "../../../lib/utils.js";
import { Button } from "../../../components/ui/button.js";
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../../../components/ui/collapsible.js";
import { getFileIcon, getFolderIcon } from "../utils/fileIcons.js";
import { jsx, jsxs } from "react/jsx-runtime";
import { ChevronDown, ChevronRight, X } from "lucide-react";
var INDENT_PX = 16, BASE_PADDING_PX = 8;
function CodeExplorerTreeNode({ node: h, depth: g, onSelectFile: _, onClearSelection: v, onCloseFile: y, isSelected: b = !1, selectedFileId: x, expandedFolders: S = /* @__PURE__ */ new Set(), toggleFolder: C }) {
	let w = S.has(h.id), T = g * INDENT_PX + BASE_PADDING_PX, E = x === h.id || b;
	if (h.type === "file") {
		let m = getFileIcon(h.name);
		return /* @__PURE__ */ jsxs("div", {
			className: cn("flex w-full min-w-0 items-center gap-2 rounded-sm py-1 group", "text-muted-foreground", E && "bg-muted"),
			style: { paddingLeft: T },
			children: [/* @__PURE__ */ jsxs("button", {
				type: "button",
				className: cn("flex flex-1 min-w-0 items-center gap-2 rounded-sm text-left text-sm hover:bg-muted/50", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"),
				onClick: () => _?.(h),
				"aria-label": `Select file ${h.name}`,
				children: [/* @__PURE__ */ jsx(m, {
					className: "h-4 w-4 shrink-0 text-muted-foreground",
					"aria-hidden": !0
				}), /* @__PURE__ */ jsx("span", {
					className: "truncate",
					children: h.name
				})]
			}), E && (y || v) && /* @__PURE__ */ jsx(Button, {
				variant: "ghost",
				size: "icon",
				className: "h-6 w-6 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",
				onClick: (e) => {
					e.stopPropagation(), y ? y(h) : v && v();
				},
				"aria-label": "Close file",
				children: /* @__PURE__ */ jsx(X, { className: "h-3.5 w-3.5" })
			})]
		});
	}
	let D = h.children && h.children.length > 0, O = getFolderIcon(w);
	return /* @__PURE__ */ jsxs(Collapsible, {
		open: w,
		onOpenChange: () => {
			C && C(h.id);
		},
		children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
			className: cn("flex w-full min-w-0 items-center gap-1 rounded-sm py-1 text-left text-sm hover:bg-muted", "text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", "disabled:cursor-default disabled:opacity-50"),
			style: { paddingLeft: T },
			disabled: !D,
			"aria-label": `${w ? "Collapse" : "Expand"} folder ${h.name}`,
			children: [
				D ? jsx(w ? ChevronDown : ChevronRight, {
					className: "h-4 w-4 shrink-0",
					"aria-hidden": !0
				}) : /* @__PURE__ */ jsx("span", {
					className: "w-4 shrink-0",
					"aria-hidden": !0
				}),
				/* @__PURE__ */ jsx(O, {
					className: "h-4 w-4 shrink-0 text-muted-foreground",
					"aria-hidden": !0
				}),
				/* @__PURE__ */ jsx("span", {
					className: "truncate",
					children: h.name
				})
			]
		}), D && /* @__PURE__ */ jsx(CollapsibleContent, {
			className: "h-full",
			children: h.children.map((e) => /* @__PURE__ */ jsx(CodeExplorerTreeNode, {
				node: e,
				depth: g + 1,
				onSelectFile: _,
				onClearSelection: v,
				onCloseFile: y,
				selectedFileId: x,
				expandedFolders: S,
				toggleFolder: C
			}, e.id))
		})]
	});
}
export { CodeExplorerTreeNode };
