import React, { useState } from 'react'; interface CheckResult { ge_id: string; lang: string; chapter: string; status: 'FOUND' | 'NOT_FOUND' | 'ERROR'; message: string; tms_url?: string; } interface CheckRecord { id: string; created_at: string; input: any; status: 'pending' | 'processing' | 'completed' | 'failed'; results: CheckResult[]; error?: string; } interface CheckHistoryProps { history: CheckRecord[]; onDelete?: (id: string) => void; } const CheckHistory: React.FC = ({ history, onDelete }) => { const [expandedId, setExpandedId] = useState(null); const [hideCompleted, setHideCompleted] = useState(false); const formatDate = (dateStr: string) => { const date = new Date(dateStr); return date.toLocaleString('vi-VN'); }; const getStatusColor = (status: string) => { switch (status) { case 'completed': return 'text-green-400'; case 'processing': return 'text-yellow-400'; case 'failed': return 'text-red-400'; default: return 'text-slate-400'; } }; const getStatusText = (status: string) => { switch (status) { case 'completed': return 'Hoàn thành'; case 'processing': return 'Đang xử lý'; case 'failed': return 'Thất bại'; default: return 'Chờ xử lý'; } }; return (

Lịch sử Check Upload

{history.length > 0 ? (
{history.map((record) => { const isExpanded = expandedId === record.id; const foundCount = record.results.filter(r => r.status === 'FOUND').length; const notFoundCount = record.results.filter(r => r.status === 'NOT_FOUND').length; const errorCount = record.results.filter(r => r.status === 'ERROR').length; // Filter results based on toggle - hide FOUND (completed) when toggle is on let displayResults = hideCompleted ? record.results.filter(r => r.status !== 'FOUND') : record.results; // Sort results by GE ID (ascending) displayResults = [...displayResults].sort((a, b) => { const aId = parseInt(a.ge_id) || 0; const bId = parseInt(b.ge_id) || 0; return aId - bId; }); // Skip record if no results to show when filter is on if (hideCompleted && displayResults.length === 0) { return null; } return (
setExpandedId(isExpanded ? null : record.id)} >
{formatDate(record.created_at)} {getStatusText(record.status)}
Tổng: {record.results.length} {foundCount > 0 && ( Đã có: {foundCount} )} {notFoundCount > 0 && ( Chưa có: {notFoundCount} )} {errorCount > 0 && ( Lỗi: {errorCount} )}
{onDelete && ( )}
{isExpanded && displayResults.length > 0 && (
{displayResults.map((result, idx) => ( ))}
GE ID LANG CHAP Trạng thái Ghi chú
{result.tms_url ? ( {result.ge_id} ) : ( {result.ge_id} )} {result.lang} {result.chapter} {result.status === 'FOUND' ? 'ĐÃ CÓ' : result.status === 'NOT_FOUND' ? 'CHƯA CÓ' : 'LỖI'} {result.message}
)}
); })}
) : (

Chưa có lịch sử check.

)}
); }; export default CheckHistory;