'use client' /** * DraftEditor - Split-Pane Editor fuer Compliance-Dokument-Entwuerfe * * Links (2/3): Gerenderter Draft mit Section-Headern * Rechts (1/3): Chat-Panel fuer iterative Verfeinerung * Oben: Document-Type Label, Depth-Level Badge, Constraint-Compliance */ import { useState, useRef, useCallback } from 'react' import { DOCUMENT_TYPE_LABELS } from '@/lib/sdk/compliance-scope-types' import type { ScopeDocumentType } from '@/lib/sdk/compliance-scope-types' import type { DraftRevision, ConstraintCheckResult, ValidationResult, } from '@/lib/sdk/drafting-engine/types' interface DraftEditorProps { draft: DraftRevision documentType: ScopeDocumentType | null constraintCheck: ConstraintCheckResult | null validationResult: ValidationResult | null isTyping: boolean onAccept: () => void onValidate: () => void onClose: () => void onRefine: (instruction: string) => void } export function DraftEditor({ draft, documentType, constraintCheck, validationResult, isTyping, onAccept, onValidate, onClose, onRefine, }: DraftEditorProps) { const [refineInput, setRefineInput] = useState('') const [activeSection, setActiveSection] = useState(null) const contentRef = useRef(null) const handleRefine = useCallback(() => { if (!refineInput.trim() || isTyping) return onRefine(refineInput.trim()) setRefineInput('') }, [refineInput, isTyping, onRefine]) const handleRefineKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault() handleRefine() } } const docLabel = documentType ? DOCUMENT_TYPE_LABELS[documentType]?.split(' (')[0] || documentType : 'Dokument' return (
{/* Header */}
{docLabel} - Entwurf
{draft.sections.length} Sections | Erstellt {new Date(draft.createdAt).toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit' })}
{/* Constraint Badge */} {constraintCheck && ( {constraintCheck.allowed ? 'Constraints OK' : 'Constraint-Verletzung'} )} {/* Validation Badge */} {validationResult && ( {validationResult.passed ? 'Validiert' : `${validationResult.errors.length} Fehler`} )}
{/* Adjustment Warnings */} {constraintCheck && constraintCheck.adjustments.length > 0 && (
{constraintCheck.adjustments.map((adj, i) => (

{adj}

))}
)} {/* Main Content: 2/3 Editor + 1/3 Chat */}
{/* Left: Draft Content (2/3) */}
{/* Section Navigation */}
{draft.sections.map((section) => ( ))}
{/* Sections */}
{draft.sections.map((section) => (

{section.title}

{section.schemaField && ( {section.schemaField} )}
{section.content}
))}
{/* Right: Refinement Chat (1/3) */}

Verfeinerung

Geben Sie Anweisungen zur Verbesserung

{/* Validation Summary (if present) */} {validationResult && (
{validationResult.errors.length > 0 && (
{validationResult.errors.length} Fehler
)} {validationResult.warnings.length > 0 && (
{validationResult.warnings.length} Warnungen
)} {validationResult.suggestions.length > 0 && (
{validationResult.suggestions.length} Vorschlaege
)}
)} {/* Refinement Area */}

Beschreiben Sie, was geaendert werden soll. Der Agent erstellt eine ueberarbeitete Version unter Beachtung der Scope-Constraints.

{/* Quick Refinement Buttons */}
{[ 'Mehr Details hinzufuegen', 'Platzhalter ausfuellen', 'Rechtliche Referenzen ergaenzen', 'Sprache vereinfachen', ].map((suggestion) => ( ))}
{/* Refinement Input */}
setRefineInput(e.target.value)} onKeyDown={handleRefineKeyDown} placeholder="Anweisung eingeben..." disabled={isTyping} className="flex-1 px-3 py-2 text-sm border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:opacity-50" />
{/* Footer Actions */}
) }