1import { imageMimeType } from "@t3tools/shared/image";
2import type { FilePreviewItem } from "../components/FilePreviewModal.types";
3import { isFileBackedComposerAttachment, type DraftComposerAttachment } from "./composerImages";
4
5export function composerImageGallery(
6 attachments: readonly DraftComposerAttachment[],
7): FilePreviewItem[] {
8 return attachments.flatMap((attachment): FilePreviewItem[] => {
9 if (attachment.type !== "image" && imageMimeType(attachment) === null) return [];
10 if (isFileBackedComposerAttachment(attachment)) {
11 return [{ kind: "image", name: attachment.name, attachment }];
12 }
13 return attachment.type === "image"
14 ? [{ kind: "image", name: attachment.name, uri: attachment.dataUrl ?? attachment.previewUri }]
15 : [];
16 });
17}