import { ChevronRight,Folder,FolderOpen,FolderPlus,Plus } from 'lucide-react'; import React,{ useMemo } from 'react'; import { cn } from '../lib/utils'; import { GroupNode } from '../types'; import { Collapsible,CollapsibleContent,CollapsibleTrigger } from './ui/collapsible'; import { ContextMenu,ContextMenuContent,ContextMenuItem,ContextMenuTrigger } from './ui/context-menu'; interface GroupTreeItemProps { node: GroupNode; depth: number; expandedPaths: Set; onToggle: (path: string) => void; onSelectGroup: (path: string) => void; selectedGroup: string | null; onEditGroup: (path: string) => void; onNewHost: (path: string) => void; onNewSubfolder: (path: string) => void; } export const GroupTreeItem: React.FC = ({ node, depth, expandedPaths, onToggle, onSelectGroup, selectedGroup, onEditGroup, onNewHost, onNewSubfolder, }) => { const isExpanded = expandedPaths.has(node.path); const hasChildren = node.children && Object.keys(node.children).length > 0; const paddingLeft = `${depth * 12 + 12}px`; const isSelected = selectedGroup === node.path; const childNodes = useMemo(() => { return node.children ? (Object.values(node.children) as unknown as GroupNode[]).sort((a, b) => a.name.localeCompare(b.name)) : []; }, [node.children]); return ( onToggle(node.path)}>
onSelectGroup(node.path)} >
{hasChildren && (
)}
{isExpanded ? : }
{node.name} {node.hosts.length > 0 && ( {node.hosts.length} )}
onNewHost(node.path)}> New Host onNewSubfolder(node.path)}> New Subfolder
{hasChildren && ( {childNodes.map((child) => ( ))} )}
); };