import { useState } from 'react' import { Check, X, Pencil, Trash2, RotateCcw, Plus, ChevronDown, ChevronUp } from 'lucide-react' import { cn } from '@/lib/utils' import type { KBImportNode, KBNodeEditRequest } from '@/types/kbAccelerator' interface NodeCardProps { node: KBImportNode onEdit: (nodeId: string, data: KBNodeEditRequest) => Promise onHighlight: (excerpt: string | null) => void } function confidenceColor(score: number): string { if (score >= 0.85) return 'border-emerald-400/40' if (score >= 0.65) return 'border-amber-400/40' return 'border-rose-500/40' } function confidenceLabel(score: number): string { if (score >= 0.85) return 'High' if (score >= 0.65) return 'Medium' return 'Low' } function confidenceTextColor(score: number): string { if (score >= 0.85) return 'text-emerald-400' if (score >= 0.65) return 'text-amber-400' return 'text-rose-500' } export function NodeCard({ node, onEdit, onHighlight }: NodeCardProps) { const [expanded, setExpanded] = useState(false) const [editMode, setEditMode] = useState(false) const [editContent, setEditContent] = useState('') const [busy, setBusy] = useState(false) const question = (node.content?.question as string) ?? '' const options = (node.content?.options as Array<{ label: string; next_node_id?: string }>) ?? [] const stepContent = (node.content?.content as string) ?? question const handleAction = async (operation: KBNodeEditRequest['operation'], extra?: Partial) => { setBusy(true) try { await onEdit(node.id, { operation, ...extra }) if (operation === 'edit') setEditMode(false) } finally { setBusy(false) } } const startEdit = () => { setEditContent(stepContent || question) setEditMode(true) } return (
onHighlight(node.source_excerpt)} onMouseLeave={() => onHighlight(null)} > {/* Header */}
{node.node_type} {confidenceLabel(node.confidence_score)} ({Math.round(node.confidence_score * 100)}%) {node.user_approved && ( Approved )} {node.user_edited && ( Edited )}
{editMode ? (