import { useState } from 'react' import { DynamicArrayField } from './DynamicArrayField' import { NodePicker } from './NodePicker' import { useTreeEditorStore } from '@/store/treeEditorStore' import { MarkdownContent } from '@/components/ui/MarkdownContent' import { InfoTip } from '@/components/common/InfoTip' import type { TreeStructure } from '@/types' import { cn } from '@/lib/utils' interface NodeFormActionProps { node: TreeStructure onUpdate: (updates: Partial) => void } export function NodeFormAction({ node, onUpdate }: NodeFormActionProps) { const { validationErrors } = useTreeEditorStore() const [showPreview, setShowPreview] = useState(false) const titleError = validationErrors.find( e => e.nodeId === node.id && e.field === 'title' ) const nextNodeError = validationErrors.find( e => e.nodeId === node.id && e.field === 'next_node_id' ) const handleAddCommand = () => { onUpdate({ commands: [...(node.commands || []), ''] }) } const handleRemoveCommand = (index: number) => { const newCommands = [...(node.commands || [])] newCommands.splice(index, 1) onUpdate({ commands: newCommands }) } const handleUpdateCommand = (index: number, value: string) => { const newCommands = [...(node.commands || [])] newCommands[index] = value onUpdate({ commands: newCommands }) } const handleReorderCommands = (fromIndex: number, toIndex: number) => { const newCommands = [...(node.commands || [])] const [moved] = newCommands.splice(fromIndex, 1) newCommands.splice(toIndex, 0, moved) onUpdate({ commands: newCommands }) } return (
{/* Title */}
onUpdate({ title: e.target.value })} placeholder="e.g., Restart the Service" className={cn( 'mt-1 block w-full rounded-md border px-3 py-2 text-sm', 'bg-card text-foreground placeholder:text-muted-foreground', 'focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary/20', titleError ? 'border-red-400' : 'border-border' )} /> {titleError && (

{titleError.message}

)}
{/* Description */}
{node.description && ( )}
{showPreview && node.description ? (
) : (