"use client";
import { useState } from "react";
import { FileTreeNode } from "@/core/types";
interface FileTreeProps {
nodes: FileTreeNode[];
onSelect: (path: string) => void;
selectedPath?: string;
}
export function FileTree({ nodes, onSelect, selectedPath }: FileTreeProps) {
return (
{nodes.map((node) => (
))}
);
}
interface FileTreeItemProps {
node: FileTreeNode;
onSelect: (path: string) => void;
selectedPath?: string;
depth: number;
}
function FileTreeItem({ node, onSelect, selectedPath, depth }: FileTreeItemProps) {
const [isExpanded, setIsExpanded] = useState(depth < 2); // Auto-expand first 2 levels
const isSelected = selectedPath === node.path;
const isDirectory = node.type === "directory";
const handleClick = () => {
if (isDirectory) {
setIsExpanded(!isExpanded);
} else {
onSelect(node.path);
}
};
return (
{/* Children */}
{isDirectory && isExpanded && node.children && (
{node.children.map((child) => (
))}
)}
);
}
function getFileIcon(filename: string): string {
if (filename.endsWith(".md")) return "📄";
if (filename.endsWith(".json")) return "📋";
if (filename.endsWith(".ts") || filename.endsWith(".tsx")) return "📜";
if (filename.endsWith(".js") || filename.endsWith(".jsx")) return "📜";
return "📄";
}