import { useState } from "react"; import { ImageIcon } from "lucide-react"; import { useTranslation } from "react-i18next"; import { ImageLightbox } from "@/components/ImageLightbox"; import type { UIImage } from "@/lib/types"; import { cn } from "@/lib/utils"; /** A bounded, quiet preview; the viewer still contains every delivered image. */ export function ImageGallery({ images, align = "left", size = "large" }: { images: UIImage[]; align?: "left" | "right"; size?: "compact" | "large"; }) { const { t } = useTranslation(); const [index, setIndex] = useState(null); const viewable = images.filter((image) => image.url); const multiple = images.length > 1; const visible = images.slice(0, 4); return <> {visible.map((image, position) => { const remaining = images.length - visible.length; const overflow = position === visible.length - 1 && remaining > 0; return setIndex(Math.max(0, viewable.indexOf(image))) : undefined} overlay={overflow ? `+${remaining}` : undefined} />; })} { if (!open) setIndex(null); }} /> ; } export function ImageThumbnail({ image, size = "large", onOpen, label, overlay, onError }: { image: UIImage; size?: "compact" | "large" | "grid"; onOpen?: () => void; label?: string; overlay?: string; onError?: () => void; }) { const { t } = useTranslation(); const [failed, setFailed] = useState(false); const classes = cn( "relative block max-w-full overflow-hidden rounded-control border border-border/60 bg-muted/25", size === "large" ? "w-[min(100%,28rem)]" : size === "grid" ? "aspect-[8/5] w-full" : "h-24 w-24", ); const content = image.url && !failed ? {image.name { setFailed(true); onError?.(); }} className={cn("block w-full object-contain", size === "large" ? "h-auto max-h-[22rem]" : "h-full")} /> : {image.name || t("message.imageAttachment")} ; if (!onOpen || ((!image.url || failed) && !overlay)) return {content}; return ; }