import { useState, useEffect } from "react"; import { BifrostOCRResponse, OCRDocument } from "@/lib/types/logs"; import { Button } from "@/components/ui/button"; import { CodeEditor } from "@/components/ui/codeEditor"; import { ChevronLeft, ChevronRight, FileText } from "lucide-react"; function getImageSrc(b64: string): string { if (b64.startsWith("/9j/")) return `data:image/jpeg;base64,${b64}`; if (b64.startsWith("iVBOR")) return `data:image/png;base64,${b64}`; if (b64.startsWith("UklGR")) return `data:image/webp;base64,${b64}`; if (b64.startsWith("R0lGO")) return `data:image/gif;base64,${b64}`; return `data:image/png;base64,${b64}`; } interface OCRViewProps { ocrInput?: OCRDocument; ocrOutput?: BifrostOCRResponse; } export default function OCRView({ ocrInput, ocrOutput }: OCRViewProps) { const pages = ocrOutput?.pages ?? []; const totalPages = pages.length; const [currentIndex, setCurrentIndex] = useState(0); useEffect(() => { if (totalPages === 0) { setCurrentIndex(0); } else { setCurrentIndex((prev) => Math.min(prev, totalPages - 1)); } }, [totalPages]); const goToPrevious = () => setCurrentIndex((prev) => (prev === 0 ? totalPages - 1 : prev - 1)); const goToNext = () => setCurrentIndex((prev) => (prev === totalPages - 1 ? 0 : prev + 1)); const currentPage = pages[currentIndex] ?? null; const pageImages = currentPage?.images?.filter((img) => img.image_base64) ?? []; return (