'use client' import React from 'react' import type { VocabWorksheetHook, IpaMode, SyllableMode } from '../types' import { getApiBase } from '../constants' export function VocabularyTab({ h }: { h: VocabWorksheetHook }) { const { isDark, glassCard, glassInput } = h const extras = h.getAllExtraColumns() const baseCols = 3 + extras.length const gridCols = `14px 32px 36px repeat(${baseCols}, 1fr) 32px` return (
{/* Left: Original pages */}

Original ({(() => { const pp = h.selectedPages.length > 0 ? h.selectedPages : [...new Set(h.vocabulary.map(v => (v.source_page || 1) - 1))]; return pp.length; })()} Seiten)

{(() => { const processedPageIndices = h.selectedPages.length > 0 ? h.selectedPages : [...new Set(h.vocabulary.map(v => (v.source_page || 1) - 1))].sort((a, b) => a - b) const apiBase = getApiBase() const pagesToShow = processedPageIndices .filter(idx => idx >= 0) .map(idx => ({ idx, src: h.session ? `${apiBase}/api/v1/vocab/sessions/${h.session.id}/pdf-page-image/${idx}` : null, })) .filter(t => t.src !== null) as { idx: number; src: string }[] if (pagesToShow.length > 0) { return pagesToShow.map(({ idx, src }) => (
S. {idx + 1}
{`Seite
)) } if (h.uploadedImage) { return (
Arbeitsblatt
) } return (

Kein Bild verfuegbar

) })()}
{/* Right: Vocabulary table */}

Vokabeln ({h.vocabulary.length})

{/* IPA mode */} {/* Syllable mode */}
{/* Error messages for failed pages */} {h.processingErrors.length > 0 && (
Einige Seiten konnten nicht verarbeitet werden:
    {h.processingErrors.map((err, idx) => (
  • • {err}
  • ))}
)} {/* Processing Progress */} {h.currentlyProcessingPage && (
Verarbeite Seite {h.currentlyProcessingPage}...
{h.successfulPages.length > 0 && `${h.successfulPages.length} Seite(n) fertig • `} {h.vocabulary.length} Vokabeln bisher
)} {/* Success info */} {!h.currentlyProcessingPage && h.successfulPages.length > 0 && h.failedPages.length === 0 && (
Alle {h.successfulPages.length} Seite(n) erfolgreich verarbeitet - {h.vocabulary.length} Vokabeln insgesamt
)} {/* Partial success info */} {!h.currentlyProcessingPage && h.successfulPages.length > 0 && h.failedPages.length > 0 && (
{h.successfulPages.length} Seite(n) erfolgreich, {h.failedPages.length} fehlgeschlagen - {h.vocabulary.length} Vokabeln extrahiert
)} {h.vocabulary.length === 0 ? (

Keine Vokabeln gefunden.

) : (
{/* Fixed Header */}
{/* insert-triangle spacer */}
0 && h.vocabulary.every(v => v.selected)} onChange={h.toggleAllSelection} className="w-4 h-4 rounded border-gray-300 text-purple-600 focus:ring-purple-500 cursor-pointer" title="Alle auswaehlen" />
S.
Englisch
Deutsch
Beispiel
{extras.map(col => (
{col.label}
))}
{/* Scrollable Content */}
{h.vocabulary.map((entry, index) => (
h.toggleVocabularySelection(entry.id)} className="w-4 h-4 rounded border-gray-300 text-purple-600 focus:ring-purple-500 cursor-pointer" />
{entry.source_page || '-'}
h.updateVocabularyEntry(entry.id, 'english', e.target.value)} className={`px-2 py-1 rounded-lg border text-sm min-w-0 ${glassInput} focus:outline-none focus:ring-1 focus:ring-purple-500`} /> h.updateVocabularyEntry(entry.id, 'german', e.target.value)} className={`px-2 py-1 rounded-lg border text-sm min-w-0 ${glassInput} focus:outline-none focus:ring-1 focus:ring-purple-500`} /> h.updateVocabularyEntry(entry.id, 'example_sentence', e.target.value)} placeholder="Beispiel" className={`px-2 py-1 rounded-lg border text-sm min-w-0 ${glassInput} focus:outline-none focus:ring-1 focus:ring-purple-500`} /> {extras.map(col => ( h.updateVocabularyEntry(entry.id, col.key, e.target.value)} placeholder={col.label} className={`px-2 py-1 rounded-lg border text-sm min-w-0 ${glassInput} focus:outline-none focus:ring-1 focus:ring-purple-500`} /> ))}
))} {/* Final insert triangle */}
{/* Footer */}
{h.vocabulary.length} Vokabeln {h.vocabulary.filter(v => v.selected).length > 0 && ` (${h.vocabulary.filter(v => v.selected).length} ausgewaehlt)`} {(() => { const pages = [...new Set(h.vocabulary.map(v => v.source_page).filter(Boolean))].sort((a, b) => (a || 0) - (b || 0)) return pages.length > 1 ? ` • Seiten: ${pages.join(', ')}` : '' })()}
)}
) }