import { IconString } from '../components/display/icon' export type AttachmentPreviewKind = 'image' | 'video' | 'file' // Document picker providers sometimes hand back assets without a usable // MIME type (Android `MediaStore` content URIs, some cloud-storage // providers). The asset's `type` then arrives as `application/octet-stream` // or undefined even though the file is genuinely an image or video. Fall // back to extension-based classification in that case so the preview // matches the actual content. const IMAGE_EXTENSIONS = new Set(['bmp', 'gif', 'heic', 'heif', 'jpeg', 'jpg', 'png', 'webp']) const VIDEO_EXTENSIONS = new Set([ '3gp', 'avi', 'h263', 'h264', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpeg4', 'mpg', 'webm', 'wmv', ]) export function pickAttachmentPreviewKind( type: string | undefined, name?: string ): AttachmentPreviewKind { if (type?.startsWith('image/')) return 'image' if (type?.startsWith('video/')) return 'video' const ext = name?.split('.').pop()?.toLowerCase() if (ext && IMAGE_EXTENSIONS.has(ext)) return 'image' if (ext && VIDEO_EXTENSIONS.has(ext)) return 'video' return 'file' } export function getAttachmentIconName(type: string | undefined): IconString { if (type?.startsWith('image/')) return 'general.outlinedImageFile' if (type?.startsWith('video/')) return 'general.outlinedVideoFile' if (type?.startsWith('audio/')) return 'general.outlinedMusicFile' if (type === 'application/pdf') return 'general.outlinedPdfFile' return 'general.outlinedGenericFile' }