import { useEffect, useState } from 'react' import { categoriesApi } from '@/api' import { useTreeEditorStore } from '@/store/treeEditorStore' import { TagInput } from '@/components/common/TagInput' import type { CategoryListItem } from '@/types' import { cn } from '@/lib/utils' import { Globe, Lock } from 'lucide-react' export function TreeMetadataForm() { const { name, description, category, categoryId, tags, isPublic, setName, setDescription, setCategory, setCategoryId, setTags, setIsPublic, validationErrors, } = useTreeEditorStore() const [categories, setCategories] = useState([]) const [customCategory, setCustomCategory] = useState(false) // Load categories useEffect(() => { categoriesApi.list().then(setCategories).catch(console.error) }, []) const handleCategoryChange = (value: string) => { if (value === '__custom__') { setCustomCategory(true) setCategory('') setCategoryId(null) } else if (value === '') { setCustomCategory(false) setCategory('') setCategoryId(null) } else { setCustomCategory(false) setCategoryId(value) // Find category name for display const cat = categories.find((c) => c.id === value) if (cat) { setCategory(cat.name) } } } const nameError = validationErrors.find( (e) => !e.nodeId && e.message.toLowerCase().includes('name') ) return (

Tree Details

{/* Name */}
setName(e.target.value)} placeholder="e.g., VDA Registration Troubleshooting" className={cn( 'mt-1 block w-full rounded-md border px-3 py-2 text-sm', 'bg-background text-foreground placeholder:text-muted-foreground', 'focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary', nameError ? 'border-destructive' : 'border-input' )} /> {nameError &&

{nameError.message}

}
{/* Description */}