"use client"; import { useState, useEffect } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { ChevronLeft, ChevronRight, ZoomIn, ZoomOut, Loader2 } from "lucide-react"; import { API_BASE } from "@/lib/api"; interface Props { documentId: string; currentPage: number; onPageChange: (page: number) => void; totalPages: number; } export default function PDFViewer({ documentId, currentPage, onPageChange, totalPages }: Props) { const [scale, setScale] = useState(1.0); const [loading, setLoading] = useState(true); const [pageInput, setPageInput] = useState(String(currentPage)); useEffect(() => { setPageInput(String(currentPage)); }, [currentPage]); const token = typeof window !== "undefined" ? localStorage.getItem("token") : null; const pdfUrl = `${API_BASE}/api/v1/documents/${documentId}/pdf`; // Use an iframe to render the PDF with the browser's native viewer // We append a page fragment for navigation const iframeSrc = `${pdfUrl}#page=${currentPage}`; const handlePageSubmit = (e: React.FormEvent) => { e.preventDefault(); const num = parseInt(pageInput.trim()); if (!isNaN(num) && num >= 1 && num <= totalPages) { onPageChange(num); } else { setPageInput(String(currentPage)); } }; return (