import type { Attachment, Post } from "../../../types/post";
import { useLightbox } from "../overlays/ImageLightbox";
import { autolink } from "../utils/autolink";
const MAX_VISIBLE = 4;
function imageRatio(att: Attachment) {
return att.width && att.height ? `${att.width} / ${att.height}` : "4 / 3";
}
export function AlbumBubble({ post }: { post: Post }) {
const { openLightbox } = useLightbox();
const images = post.attachments;
const shouldMerge = images.length > MAX_VISIBLE;
if (!shouldMerge) {
return (
{images.map((att, i) => (
))}
{post.text ? (
{autolink(post.text)}
) : null}
);
}
const visible = images.slice(0, MAX_VISIBLE);
const extra = images.length - MAX_VISIBLE;
return (
{visible.map((att, i) => {
const isLastSlot = i === MAX_VISIBLE - 1 && extra > 0;
return (
);
})}
{post.text ? (
{autolink(post.text)}
) : null}
);
}