'use client' import React, { useState, useRef } from 'react' interface DocumentRowProps { label: string docType: string required?: boolean url: string text: string loading: boolean error: string | null wordCount: number onUrlChange: (url: string) => void onFetchText: () => void onTextChange: (text: string) => void onFileUpload: (file: File) => void } export function DocumentRow({ label, docType, required, url, text, loading, error, wordCount, onUrlChange, onFetchText, onTextChange, onFileUpload, }: DocumentRowProps) { const [showText, setShowText] = useState(false) const fileRef = useRef(null) const textVisible = showText || text.length > 0 const handleFileChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0] if (!file) return // Read text-based files directly const reader = new FileReader() reader.onload = () => { const content = reader.result as string onTextChange(content) } reader.onerror = () => { // Let parent handle via onFileUpload for binary formats onFileUpload(file) } if (file.name.endsWith('.txt') || file.type === 'text/plain') { reader.readAsText(file) } else { // PDF, DOCX — pass to parent for server-side parsing onFileUpload(file) } // Reset input so the same file can be re-selected e.target.value = '' } return (
{/* Header row: label + inputs */}
{label} {required && *}
onUrlChange(e.target.value)} placeholder="https://example.com/datenschutz" className="flex-1 px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-purple-500 focus:border-transparent" /> {/* Fetch text button */} {/* File upload button */} {/* Toggle text area */} {/* Word count badge */} {wordCount > 0 && ( {wordCount.toLocaleString('de-DE')} W. )}
{/* Error */} {error && (
{error}
)} {/* Collapsible textarea */} {textVisible && (