import { useEffect, useRef, useState } from 'react'; import { renderExamPdfPages } from '../utils/renderExamPdf'; interface Props { title: string; bytes: Uint8Array | null; loading?: boolean; onClose: () => void; } export function ExamPaperPdfModal({ title, bytes, loading, onClose }: Props) { const containerRef = useRef(null); const [err, setErr] = useState(''); useEffect(() => { if (!bytes || !containerRef.current) return; let cancelled = false; setErr(''); renderExamPdfPages(containerRef.current, bytes).catch((e: unknown) => { if (!cancelled) { setErr(e instanceof Error ? e.message : 'Không hiển thị được PDF'); } }); return () => { cancelled = true; }; }, [bytes]); return (
e.stopPropagation()}>

{title}

{loading &&

Đang tải đề...

} {err &&

{err}

} {!loading && !bytes && !err && (

Không có dữ liệu PDF

)}
); }