"use client"; import { useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { Download, CheckCircle2, X } from "lucide-react"; import { type GalleryImage } from "./ImageGallery"; /** Trigger a browser download for a gallery image (no-op when it has no src). */ /** True when the src URL path (query string ignored) ends in .pdf. */ export function isPdfSrc(src?: string): boolean { if (!src) return false; try { return new URL(src, "http://localhost").pathname.toLowerCase().endsWith(".pdf"); } catch { return false; } } export function downloadGalleryImage(img: GalleryImage) { if (!img.src) return; const a = document.createElement("a"); a.href = img.src; a.download = `${img.title.replace(/\s+/g, "_").toLowerCase()}.${isPdfSrc(img.src) ? "pdf" : "png"}`; a.target = "_blank"; document.body.appendChild(a); a.click(); document.body.removeChild(a); } interface Props { /** image to preview; null closes the lightbox */ image: GalleryImage | null; onClose: () => void; } /** Fullscreen image preview overlay with a download action. */ export default function ImageLightbox({ image, onClose }: Props) { const [saved, setSaved] = useState(false); const handleDownload = () => { if (image) downloadGalleryImage(image); setSaved(true); setTimeout(() => setSaved(false), 2200); }; return ( {image && ( <> {/* Close */} {/* Image — natural ratio, full modal width, height auto */}
{image.src ? ( // eslint-disable-next-line @next/next/no-img-element -- arbitrary remote image URLs; next/image would require per-host remotePatterns config and fixed dimensions. {image.title} ) : (

{image.title}

)}
{/* Title + download */}

{image.title}

{ e.stopPropagation(); handleDownload(); }} whileTap={{ scale: 0.9 }} className="flex items-center gap-1.5 px-3 py-2 rounded-xl text-xs font-bold" style={{ background: saved ? "rgba(34,197,94,0.2)" : "rgba(255,107,0,0.2)", border: `1px solid ${saved ? "rgba(34,197,94,0.4)" : "rgba(255,107,0,0.4)"}`, color: saved ? "#22c55e" : "#FF6B00", }} > {saved ? ( <> Saved ) : ( <> View )}
)} ); }