'use client' import React from 'react' import { STRUCTURAL_KEYS, HIDDEN_KEYS } from './ChunkBrowserConstants' import { getChunkText, getStructuralInfo } from './ChunkBrowserHelpers' import { RAG_PDF_MAPPING } from './rag-pdf-mapping' import { REGULATIONS_IN_RAG } from '../rag-constants' interface ChunkBrowserContentProps { selectedRegulation: string | null docLoading: boolean docChunks: Record[] docChunkIndex: number docTotalChunks: number splitViewActive: boolean chunksPerPage: number pdfExists: boolean | null } export function ChunkBrowserContent({ selectedRegulation, docLoading, docChunks, docChunkIndex, docTotalChunks, splitViewActive, chunksPerPage, pdfExists, }: ChunkBrowserContentProps) { const currentChunk = docChunks[docChunkIndex] || null const prevChunk = docChunkIndex > 0 ? docChunks[docChunkIndex - 1] : null const nextChunk = docChunkIndex < docChunks.length - 1 ? docChunks[docChunkIndex + 1] : null const structInfo = getStructuralInfo(currentChunk) // PDF page estimation const estimatePdfPage = (chunk: Record | null, chunkIdx: number): number => { if (chunk) { const pages = chunk.pages as number[] | undefined if (Array.isArray(pages) && pages.length > 0) return pages[0] const page = chunk.page as number | undefined if (typeof page === 'number' && page > 0) return page } const mapping = selectedRegulation ? RAG_PDF_MAPPING[selectedRegulation] : null const cpp = mapping?.chunksPerPage || chunksPerPage return Math.floor(chunkIdx / cpp) + 1 } const pdfPage = estimatePdfPage(currentChunk, docChunkIndex) const pdfMapping = selectedRegulation ? RAG_PDF_MAPPING[selectedRegulation] : null const pdfUrl = pdfMapping ? `/rag-originals/${pdfMapping.filename}#page=${pdfPage}` : null // Overlap extraction const getOverlapPrev = (): string => { if (!prevChunk) return '' const text = getChunkText(prevChunk) return text.length > 150 ? '...' + text.slice(-150) : text } const getOverlapNext = (): string => { if (!nextChunk) return '' const text = getChunkText(nextChunk) return text.length > 150 ? text.slice(0, 150) + '...' : text } if (!selectedRegulation) { return (
🔍

Dokument in der Sidebar auswaehlen, um QA zu starten.

Pfeiltasten: Chunk vor/zurueck

) } if (docLoading) { return (

Chunks werden geladen...

{selectedRegulation}: {REGULATIONS_IN_RAG[selectedRegulation]?.chunks.toLocaleString() || '?'} Chunks erwartet

) } return (
{/* Chunk-Text Panel */}
Chunk-Text
{structInfo.article && ( {structInfo.article} )} {structInfo.section && ( {structInfo.section} )} #{docChunkIndex} / {docTotalChunks - 1}
{/* Overlap from previous chunk */} {prevChunk && (
↑ Ende vorheriger Chunk #{docChunkIndex - 1}

{getOverlapPrev()}

)} {/* Current chunk text */} {currentChunk ? (
{getChunkText(currentChunk)}
) : (
Kein Chunk-Text vorhanden.
)} {/* Overlap from next chunk */} {nextChunk && (
↓ Anfang naechster Chunk #{docChunkIndex + 1}

{getOverlapNext()}

)} {/* Metadata */} {currentChunk && (
Metadaten
{Object.entries(currentChunk) .filter(([k]) => !HIDDEN_KEYS.has(k)) .sort(([a], [b]) => { const aStruct = STRUCTURAL_KEYS.has(a) ? 0 : 1 const bStruct = STRUCTURAL_KEYS.has(b) ? 0 : 1 return aStruct - bStruct || a.localeCompare(b) }) .map(([k, v]) => (
{k}: {Array.isArray(v) ? v.join(', ') : String(v)}
))}
Chunk-Laenge: {getChunkText(currentChunk).length} Zeichen {getChunkText(currentChunk).length < 50 && ( ⚠ Sehr kurz )} {getChunkText(currentChunk).length > 2000 && ( ⚠ Sehr lang )}
)}
{/* PDF-Viewer Panel */} {splitViewActive && (
Original-PDF
Seite ~{pdfPage} {pdfMapping?.totalPages ? ` / ${pdfMapping.totalPages}` : ''} {pdfUrl && ( Oeffnen ↗ )}
{pdfUrl && pdfExists ? (