"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { ChevronRight, ChevronDown, File, Folder } from "lucide-react";
import { cn } from "../../lib/utils";
function FileTree({
  nodes,
  selectedPath,
  expandedFolders,
  onSelectFile,
  onToggleFolder,
  level = 0
}) {
  if (!nodes || nodes.length === 0) {
    return null;
  }
  const isFolderInSelectionPath = (folderPath) => {
    if (!selectedPath) return false;
    return selectedPath.startsWith(folderPath + "/");
  };
  return /* @__PURE__ */ jsx("div", { className: "space-y-0.5", children: nodes.map((node) => {
    const isExpanded = expandedFolders.has(node.path);
    const isSelected = selectedPath === node.path;
    const isInPath = isFolderInSelectionPath(node.path);
    const paddingLeft = level * 12 + 8;
    if (node.type === "folder") {
      return /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsxs(
          "button",
          {
            onClick: () => onToggleFolder(node.path),
            className: cn(
              "w-full flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-accent transition-colors text-left",
              "text-sm",
              isInPath && "bg-violet-50 dark:bg-violet-950/30"
            ),
            style: { paddingLeft: `${paddingLeft}px` },
            "data-cy": `dev-tests-folder-${node.name}`,
            "aria-expanded": isExpanded,
            children: [
              isExpanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-4 w-4 flex-shrink-0 text-muted-foreground" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-4 w-4 flex-shrink-0 text-muted-foreground" }),
              /* @__PURE__ */ jsx(
                Folder,
                {
                  className: cn(
                    "h-4 w-4 flex-shrink-0",
                    isInPath ? "text-violet-600 dark:text-violet-400" : "text-violet-600 dark:text-violet-400"
                  )
                }
              ),
              /* @__PURE__ */ jsx(
                "span",
                {
                  className: cn("font-medium", isInPath && "text-violet-700 dark:text-violet-300"),
                  children: node.name
                }
              )
            ]
          }
        ),
        isExpanded && node.children && /* @__PURE__ */ jsx(
          FileTree,
          {
            nodes: node.children,
            selectedPath,
            expandedFolders,
            onSelectFile,
            onToggleFolder,
            level: level + 1
          }
        )
      ] }, node.path);
    }
    return /* @__PURE__ */ jsxs(
      "button",
      {
        onClick: () => onSelectFile(node.path),
        className: cn(
          "w-full flex items-center gap-2 px-2 py-1.5 rounded-md transition-colors text-left",
          "text-sm hover:bg-accent",
          isSelected && "bg-violet-100 dark:bg-violet-950 text-violet-700 dark:text-violet-300 font-medium"
        ),
        style: { paddingLeft: `${paddingLeft + 20}px` },
        "data-cy": `dev-tests-file-${node.name.replace(".md", "")}`,
        children: [
          /* @__PURE__ */ jsx(File, { className: "h-4 w-4 flex-shrink-0" }),
          /* @__PURE__ */ jsx("span", { children: node.name })
        ]
      },
      node.path
    );
  }) });
}
export {
  FileTree
};
