'use client' /** * AnnotationPanel * * Panel for viewing, editing, and managing annotations. * Shows a list of all annotations with options to edit text, change severity, or delete. */ import { useState } from 'react' import type { Annotation, AnnotationType } from '../types' import { ANNOTATION_COLORS } from '../types' interface AnnotationPanelProps { annotations: Annotation[] selectedAnnotation: Annotation | null onSelectAnnotation: (annotation: Annotation | null) => void onUpdateAnnotation: (id: string, updates: Partial) => void onDeleteAnnotation: (id: string) => void } const SEVERITY_OPTIONS = [ { value: 'minor', label: 'Leicht', color: '#fbbf24' }, { value: 'major', label: 'Mittel', color: '#f97316' }, { value: 'critical', label: 'Schwer', color: '#dc2626' }, ] as const const TYPE_LABELS: Record = { rechtschreibung: 'Rechtschreibung', grammatik: 'Grammatik', inhalt: 'Inhalt', struktur: 'Struktur', stil: 'Stil', comment: 'Kommentar', highlight: 'Markierung', } export default function AnnotationPanel({ annotations, selectedAnnotation, onSelectAnnotation, onUpdateAnnotation, onDeleteAnnotation, }: AnnotationPanelProps) { const [editingId, setEditingId] = useState(null) const [editText, setEditText] = useState('') const [editSuggestion, setEditSuggestion] = useState('') // Group annotations by type const groupedAnnotations = annotations.reduce( (acc, ann) => { if (!acc[ann.type]) { acc[ann.type] = [] } acc[ann.type].push(ann) return acc }, {} as Record ) const handleEdit = (annotation: Annotation) => { setEditingId(annotation.id) setEditText(annotation.text) setEditSuggestion(annotation.suggestion || '') } const handleSaveEdit = (id: string) => { onUpdateAnnotation(id, { text: editText, suggestion: editSuggestion || undefined }) setEditingId(null) setEditText('') setEditSuggestion('') } const handleCancelEdit = () => { setEditingId(null) setEditText('') setEditSuggestion('') } if (annotations.length === 0) { return (

Keine Annotationen vorhanden

Waehlen Sie ein Werkzeug und markieren Sie Stellen im Dokument

) } return (
{/* Summary */}
{annotations.length} Annotationen
{Object.entries(groupedAnnotations).map(([type, anns]) => ( {anns.length} ))}
{/* Annotations list by type */}
{(Object.entries(groupedAnnotations) as [AnnotationType, Annotation[]][]).map(([type, anns]) => (
{/* Type header */}
{TYPE_LABELS[type]} ({anns.length})
{/* Annotations in this type */} {anns.map((annotation) => { const isSelected = selectedAnnotation?.id === annotation.id const isEditing = editingId === annotation.id const severityInfo = SEVERITY_OPTIONS.find((s) => s.value === annotation.severity) return (
onSelectAnnotation(isSelected ? null : annotation)} > {isEditing ? ( /* Edit mode */
e.stopPropagation()}>