import { ChevronDown, AlertCircle, CheckCircle2, Loader2, Plus, HelpCircle } from 'lucide-react' import { useState, useRef, useEffect } from 'react' import { cn } from '@/lib/utils' import type { TreeMarkdownValidationError } from '@/types' interface CodeModeToolbarProps { validationErrors: TreeMarkdownValidationError[] isValidating: boolean isValid: boolean onInsertTemplate: (template: string) => void onToggleSyntaxHelp: () => void syntaxHelpOpen: boolean } const NODE_TEMPLATES = { decision: [ '', '---', 'id: new_decision', 'type: decision', 'parent: root', '---', '# What is the question?', '', '> Help text for the engineer', '', '- [A] Option A → @target_id', '- [B] Option B → @target_id', '', ].join('\n'), action: [ '', '---', 'id: new_action', 'type: action', 'parent: root', '---', '## Action Title', '', 'Description of what to do.', '', '```commands', 'command here', '```', '', '**Expected:** Expected outcome', '', '→ @next_node_id', '', ].join('\n'), solution: [ '', '---', 'id: new_solution', 'type: solution', 'parent: root', '---', '## Solution Title', '', 'Description of the resolution.', '', '1. Step 1', '2. Step 2', '', ].join('\n'), } export function CodeModeToolbar({ validationErrors, isValidating, isValid, onInsertTemplate, onToggleSyntaxHelp, syntaxHelpOpen, }: CodeModeToolbarProps) { const [insertOpen, setInsertOpen] = useState(false) const dropdownRef = useRef(null) const errorCount = validationErrors.filter(e => e.severity === 'error').length const warningCount = validationErrors.filter(e => e.severity === 'warning').length // Close dropdown on outside click useEffect(() => { const handler = (e: MouseEvent) => { if (dropdownRef.current && !dropdownRef.current.contains(e.target as Node)) { setInsertOpen(false) } } document.addEventListener('mousedown', handler) return () => document.removeEventListener('mousedown', handler) }, []) return (
{/* Insert Node dropdown */}
{insertOpen && (
)}
{/* Validation status */}
{isValidating ? ( <> Validating... ) : isValid ? ( <> Synced {warningCount > 0 && ( ({warningCount} warning{warningCount !== 1 ? 's' : ''}) )} ) : ( <> {errorCount} error{errorCount !== 1 ? 's' : ''} {warningCount > 0 && ( , {warningCount} warning{warningCount !== 1 ? 's' : ''} )} )}
{/* Syntax Help toggle */}
) }