"use client"; import { useEffect, useRef } from "react"; import { AnimatePresence, motion } from "framer-motion"; import { X, Download } from "lucide-react"; import type { GalleryImage } from "./ImageGallery"; import { downloadGalleryImage } from "./ImageLightbox"; import type { PdfDocument } from "./pdfDocument"; /** Pages rendered by the reader; longer PDFs link out to the full file. */ export const PDF_PAGE_CAP = 5; /** Draws one PDF page onto a canvas at the device pixel ratio, sized to its container width. */ function PdfPageCanvas({ doc, page, title }: { doc: PdfDocument; page: number; title: string }) { const ref = useRef(null); useEffect(() => { let cancelled = false; doc.getPage(page).then((p) => { const canvas = ref.current; if (cancelled || !canvas) return; const cssWidth = canvas.parentElement?.clientWidth || 600; const base = p.getViewport({ scale: 1 }); const viewport = p.getViewport({ scale: (cssWidth / base.width) * (window.devicePixelRatio || 1) }); canvas.width = viewport.width; canvas.height = viewport.height; return p.render({ canvas, viewport }).promise; }).catch(() => {}); return () => { cancelled = true; }; }, [doc, page]); return ; } /** Renders pages 1..min(numPages, maxPages) stacked vertically. */ export function PdfPages({ doc, title, maxPages }: { doc: PdfDocument; title: string; maxPages: number }) { const count = Math.min(doc.numPages, maxPages); return ( <> {Array.from({ length: count }, (_, i) => ( ))} ); } interface Props { /** PDF to read; null closes the reader */ pdf: { image: GalleryImage; doc: PdfDocument } | null; onClose: () => void; } /** Fullscreen in-app PDF reader: up to PDF_PAGE_CAP pages, then a link to the full file. */ export default function PdfReader({ pdf, onClose }: Props) { return ( {pdf && ( {/* Header: title, download, close */}

{pdf.image.title}

downloadGalleryImage(pdf.image)} whileTap={{ scale: 0.9 }} className="flex items-center gap-1.5 px-3 py-2 rounded-xl text-xs font-bold" style={{ background: "rgba(255,107,0,0.2)", border: "1px solid rgba(255,107,0,0.4)", color: "#FF6B00" }} > View
{/* Pages */}
{pdf.doc.numPages > PDF_PAGE_CAP && (

Showing {PDF_PAGE_CAP} of {pdf.doc.numPages} pages

Open full PDF
)}
)}
); }