'use client' import { useState } from 'react' import { DOCUMENT_CATEGORIES, type DocumentCategory } from '@/app/(admin)/ai/ocr-pipeline/types' import type { SessionListItem, DocumentGroupView } from '@/app/(admin)/ai/ocr-kombi/useKombiPipeline' const KLAUSUR_API = '/klausur-api' interface SessionListProps { items: (SessionListItem | DocumentGroupView)[] loading: boolean activeSessionId: string | null onOpenSession: (sid: string) => void onNewSession: () => void onDeleteSession: (sid: string) => void onRenameSession: (sid: string, newName: string) => void onUpdateCategory: (sid: string, category: DocumentCategory) => void } function isGroup(item: SessionListItem | DocumentGroupView): item is DocumentGroupView { return 'group_id' in item } export function SessionList({ items, loading, activeSessionId, onOpenSession, onNewSession, onDeleteSession, onRenameSession, onUpdateCategory, }: SessionListProps) { const [editingName, setEditingName] = useState(null) const [editNameValue, setEditNameValue] = useState('') const [editingCategory, setEditingCategory] = useState(null) const [expandedGroups, setExpandedGroups] = useState>(new Set()) const toggleGroup = (groupId: string) => { setExpandedGroups(prev => { const next = new Set(prev) if (next.has(groupId)) next.delete(groupId) else next.add(groupId) return next }) } return (

Sessions ({items.length})

{loading ? (
Lade Sessions...
) : items.length === 0 ? (
Noch keine Sessions vorhanden.
) : (
{items.map(item => isGroup(item) ? ( toggleGroup(item.group_id)} onOpenSession={onOpenSession} onDeleteSession={onDeleteSession} /> ) : ( onOpenSession(item.id)} onStartRename={() => { setEditNameValue(item.name || item.filename) setEditingName(item.id) }} onFinishRename={(newName) => { onRenameSession(item.id, newName) setEditingName(null) }} onCancelRename={() => setEditingName(null)} onEditNameChange={setEditNameValue} onToggleCategory={() => setEditingCategory(editingCategory === item.id ? null : item.id)} onUpdateCategory={(cat) => { onUpdateCategory(item.id, cat) setEditingCategory(null) }} onDelete={() => { if (confirm('Session loeschen?')) onDeleteSession(item.id) }} /> ) )}
)}
) } // ---- Group row (multi-page document) ---- function GroupRow({ group, expanded, activeSessionId, onToggle, onOpenSession, onDeleteSession, }: { group: DocumentGroupView expanded: boolean activeSessionId: string | null onToggle: () => void onOpenSession: (sid: string) => void onDeleteSession: (sid: string) => void }) { const isActive = group.sessions.some(s => s.id === activeSessionId) return (
{expanded ? '\u25BC' : '\u25B6'}
{group.title}
{group.page_count} Seiten
Dokument
{expanded && (
{group.sessions.map(s => (
onOpenSession(s.id)} > {/* Thumbnail */}
{/* eslint-disable-next-line @next/next/no-img-element */} { (e.target as HTMLImageElement).style.display = 'none' }} />
S. {s.page_number || '?'} Step {s.current_step}
))}
)}
) } // ---- Single session row ---- function SessionRow({ session, isActive, editingName, editNameValue, editingCategory, onOpenSession, onStartRename, onFinishRename, onCancelRename, onEditNameChange, onToggleCategory, onUpdateCategory, onDelete, }: { session: SessionListItem isActive: boolean editingName: string | null editNameValue: string editingCategory: string | null onOpenSession: () => void onStartRename: () => void onFinishRename: (name: string) => void onCancelRename: () => void onEditNameChange: (val: string) => void onToggleCategory: () => void onUpdateCategory: (cat: DocumentCategory) => void onDelete: () => void }) { const catInfo = DOCUMENT_CATEGORIES.find(c => c.value === session.document_category) const isEditing = editingName === session.id return (
{/* Thumbnail */}
{/* eslint-disable-next-line @next/next/no-img-element */} { (e.target as HTMLImageElement).style.display = 'none' }} />
{/* Info */}
{isEditing ? ( onEditNameChange(e.target.value)} onBlur={() => onFinishRename(editNameValue)} onKeyDown={(e) => { if (e.key === 'Enter') onFinishRename(editNameValue) if (e.key === 'Escape') onCancelRename() }} onClick={(e) => e.stopPropagation()} className="w-full px-1 py-0.5 text-sm border rounded dark:bg-gray-700 dark:border-gray-600" /> ) : (
{session.name || session.filename}
)}
{new Date(session.created_at).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: '2-digit', hour: '2-digit', minute: '2-digit', })}
{/* Category badge */}
e.stopPropagation()}>
{/* Actions */}
{/* Category dropdown */} {editingCategory === session.id && (
e.stopPropagation()} > {DOCUMENT_CATEGORIES.map(cat => ( ))}
)}
) }