import { cn } from '@/lib/utils' import type { UIComponent } from '@/types/json-ui' import type { ComponentTreeWrapperProps } from './interfaces' const renderTreeNodes = ( components: UIComponent[], depth: number, selectedId: string | null, onSelect?: (id: string) => void ) => { return components.map((component) => { const hasChildren = Array.isArray(component.children) && component.children.length > 0 const isSelected = selectedId === component.id return (
{hasChildren && (
{renderTreeNodes(component.children as UIComponent[], depth + 1, selectedId, onSelect)}
)}
) }) } export function ComponentTreeWrapper({ components = [], selectedId = null, emptyMessage = 'No components available.', onSelect, className, }: ComponentTreeWrapperProps) { return (
{components.length === 0 ? (

{emptyMessage}

) : (
{renderTreeNodes(components, 0, selectedId, onSelect)}
)}
) }