import { Play } from 'lucide-react' import { DynamicArrayField } from './DynamicArrayField' import { NodePicker } from './NodePicker' import { useTreeEditorStore } from '@/store/treeEditorStore' import type { TreeStructure, TreeOption } from '@/types' import { cn } from '@/lib/utils' interface NodeFormDecisionProps { node: TreeStructure onUpdate: (updates: Partial) => void } // Convert index to letter (0=A, 1=B, 2=C, etc.) const indexToLetter = (index: number): string => { return String.fromCharCode(65 + index) // 65 is ASCII for 'A' } export function NodeFormDecision({ node, onUpdate }: NodeFormDecisionProps) { const { reorderOptions, validationErrors } = useTreeEditorStore() const isRootNode = node.id === 'root' const questionError = validationErrors.find( e => e.nodeId === node.id && e.field === 'question' ) const optionsError = validationErrors.find( e => e.nodeId === node.id && e.field === 'options' ) const handleAddOption = () => { const newOption: TreeOption = { id: crypto.randomUUID(), label: '', next_node_id: '' } onUpdate({ options: [...(node.options || []), newOption] }) } const handleRemoveOption = (index: number) => { const newOptions = [...(node.options || [])] newOptions.splice(index, 1) onUpdate({ options: newOptions }) } const handleUpdateOption = (index: number, updates: Partial) => { const newOptions = [...(node.options || [])] newOptions[index] = { ...newOptions[index], ...updates } onUpdate({ options: newOptions }) } const handleReorderOptions = (fromIndex: number, toIndex: number) => { reorderOptions(node.id, fromIndex, toIndex) } return (
{/* Root node banner */} {isRootNode && (

Starting Question

This is the first question users will see when they start this troubleshooting tree. Each option below creates a different troubleshooting path.

)} {/* Question */}
{isRootNode && (

What's the main question to diagnose the issue?

)} onUpdate({ question: e.target.value })} placeholder={isRootNode ? "e.g., What type of issue are you experiencing?" : "e.g., Can you ping the server?"} 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', questionError ? 'border-destructive' : 'border-input' )} /> {questionError && (

{questionError.message}

)}
{/* Help Text */}