'use client';


import { cn } from "../../utils/cn.mjs";
import { MaxHeightSmoother } from "../MaxHeightSmoother/index.mjs";
import { createFileTree } from "./createFileTree.mjs";
import { useState } from "react";
import { ChevronRight } from "lucide-react";
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";

//#region src/components/IDE/FileTree.tsx
const concatFilePath = (paths) => paths.join("/");
const FileItem = ({ filesPaths, path, subPath, onClickFile, activeFile, prePaths, isFile }) => {
	const [subPathOpen, setSubPathOpen] = useState(true);
	const level = prePaths.length + 1;
	const currentPath = concatFilePath([...prePaths.slice(level - 1, level), path]);
	const totalPath = concatFilePath([...prePaths, path]);
	const newPath = filesPaths.map((path$1) => path$1.replace(/^\/?/, "")).filter((filePath) => filePath.startsWith(currentPath)).map((path$1) => path$1.replace(currentPath, "").replace(/^\/?/, ""));
	const isActive = totalPath === activeFile;
	const indentation = new Array(level).fill("  ").join("");
	return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("button", {
		className: cn("flex w-full items-start justify-start whitespace-pre text-nowrap px-2 py-1 text-xs transition", isActive ? "bg-neutral-200 dark:bg-neutral-700" : "cursor-pointer hover:bg-neutral-300 dark:hover:bg-neutral-900"),
		onClick: () => {
			if (isFile) onClickFile?.(totalPath);
			else setSubPathOpen(!subPathOpen);
		},
		children: [
			/* @__PURE__ */ jsx("span", {
				className: cn("whitespace-pre", isFile && "ml-2"),
				children: indentation
			}),
			!isFile && /* @__PURE__ */ jsx(ChevronRight, {
				className: cn(`transition`, subPathOpen && `rotate-90 transform`),
				size: 16
			}),
			path
		]
	}, path), subPath && /* @__PURE__ */ jsx(MaxHeightSmoother, {
		isHidden: !subPathOpen,
		className: "overflow-x-hidden",
		children: /* @__PURE__ */ jsx(FileTree, {
			filesPaths: newPath,
			activeFile,
			onClickFile,
			prePaths: [...prePaths, path]
		})
	})] });
};
const FileTree = ({ filesPaths, activeFile, onClickFile, prePaths = [] }) => {
	return /* @__PURE__ */ jsx("div", {
		className: "flex size-full flex-col items-start justify-start py-1 text-neutral",
		children: createFileTree(filesPaths).map(({ path, subPath, isFile }) => /* @__PURE__ */ jsx(FileItem, {
			isFile,
			subPath,
			path,
			onClickFile,
			activeFile,
			prePaths,
			filesPaths
		}, path))
	});
};

//#endregion
export { FileTree };
//# sourceMappingURL=FileTree.mjs.map