import { cn } from "../../lib/utils.js";
import { Input } from "../../components/ui/input.js";
import { useCodeExplorerContext } from "./providers/CodeExplorerProvider.js";
import { CodeExplorerTree } from "./components/CodeExplorerTree.js";
import { c } from "react/compiler-runtime";
import { jsx, jsxs } from "react/jsx-runtime";
function CodeExplorer(s) {
	let l = c(20), { className: u } = s, { fileTree: d, isTreeLoading: f, error: p, searchQuery: m, setSearchQuery: h, selectFile: g, selectedFile: _, clearSelection: v, closeFile: y } = useCodeExplorerContext(), b;
	l[0] === u ? b = l[1] : (b = cn("flex h-full w-full flex-col gap-2 overflow-hidden", u), l[0] = u, l[1] = b);
	let x;
	l[2] === h ? x = l[3] : (x = (e) => h(e.target.value), l[2] = h, l[3] = x);
	let S;
	l[4] !== m || l[5] !== x ? (S = /* @__PURE__ */ jsx("div", {
		className: "flex shrink-0 flex-col gap-2",
		children: /* @__PURE__ */ jsx(Input, {
			type: "search",
			placeholder: "Search files...",
			value: m,
			onChange: x,
			className: "h-8 w-full",
			"aria-label": "Search files"
		})
	}), l[4] = m, l[5] = x, l[6] = S) : S = l[6];
	let C;
	l[7] !== v || l[8] !== y || l[9] !== p || l[10] !== d || l[11] !== f || l[12] !== m || l[13] !== g || l[14] !== _?.id ? (C = /* @__PURE__ */ jsx("div", {
		className: "flex min-h-0 flex-1 flex-col overflow-hidden",
		children: /* @__PURE__ */ jsx("div", {
			className: "flex min-h-0 flex-1 flex-col overflow-hidden rounded-md border bg-background",
			children: p ? /* @__PURE__ */ jsx("div", {
				className: "flex flex-1 flex-col items-center justify-center p-6 text-center",
				children: /* @__PURE__ */ jsxs("div", {
					className: "rounded-lg border border-destructive bg-destructive/10 p-4 max-w-md",
					children: [/* @__PURE__ */ jsx("p", {
						className: "text-sm font-semibold text-destructive mb-2",
						children: "File Explorer Error"
					}), /* @__PURE__ */ jsx("p", {
						className: "text-xs text-destructive/90",
						children: p.message
					})]
				})
			}) : f ? /* @__PURE__ */ jsx("div", {
				className: "flex flex-1 items-center justify-center p-4",
				children: /* @__PURE__ */ jsx("p", {
					className: "text-xs text-muted-foreground",
					children: "Loading file tree..."
				})
			}) : d.length === 0 ? /* @__PURE__ */ jsx("div", {
				className: "flex flex-1 items-center justify-center p-4",
				children: /* @__PURE__ */ jsx("p", {
					className: "text-xs text-muted-foreground",
					children: "No files found"
				})
			}) : /* @__PURE__ */ jsx(CodeExplorerTree, {
				nodes: d,
				searchQuery: m,
				onSelectFile: g,
				onClearSelection: v,
				onCloseFile: y,
				selectedFileId: _?.id
			})
		})
	}), l[7] = v, l[8] = y, l[9] = p, l[10] = d, l[11] = f, l[12] = m, l[13] = g, l[14] = _?.id, l[15] = C) : C = l[15];
	let w;
	return l[16] !== b || l[17] !== S || l[18] !== C ? (w = /* @__PURE__ */ jsxs("div", {
		className: b,
		children: [S, C]
	}), l[16] = b, l[17] = S, l[18] = C, l[19] = w) : w = l[19], w;
}
export { CodeExplorer };
