import { useMemo, useState } from 'react'; import type { ConversationAttachmentIndex, ConversationAttachmentItem, } from '../lib/conversationFeatures'; import { AttachmentGeneric } from './AttachmentGeneric'; import { AttachmentImage } from './AttachmentImage'; import { ArrowRightIcon, FileIcon, ImageIcon, MicIcon, VideoIcon, XIcon } from './icons'; type DrawerTab = 'media' | 'files' | 'audio'; interface Props { open: boolean; index: ConversationAttachmentIndex; senderNameFor: (senderId: string) => string; onJumpToMessage: (messageId: string) => void; onClose: () => void; } const TAB_LABELS: Record = { media: 'Medien', files: 'Dateien', audio: 'Audio', }; export function MediaFilesDrawer({ open, index, senderNameFor, onJumpToMessage, onClose }: Props) { const [tab, setTab] = useState('media'); const items = index[tab]; if (!open) return null; return ( ); } function MediaTile({ item, senderName, onJumpToMessage, }: { item: ConversationAttachmentItem; senderName: string; onJumpToMessage: (messageId: string) => void; }) { const isImage = item.handle.mimeType.startsWith('image/'); const isVideo = item.handle.mimeType.startsWith('video/'); return (
{isImage ? (
) : isVideo ? (
Video
) : ( )}
); } function FileRow({ item, senderName, onJumpToMessage, }: { item: ConversationAttachmentItem; senderName: string; onJumpToMessage: (messageId: string) => void; }) { const isAudio = item.handle.mimeType.startsWith('audio/'); return (
{isAudio ? : }

{labelFor(item.handle.mimeType)}

{formatSize(item.handle.sizeBytes)} · {senderName}

{!isAudio && }
); } function AttachmentMeta({ item, senderName, onJumpToMessage, compact = false, }: { item: ConversationAttachmentItem; senderName: string; onJumpToMessage: (messageId: string) => void; compact?: boolean; }) { const date = useMemo( () => new Intl.DateTimeFormat(undefined, { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit', }).format(new Date(item.createdAt)), [item.createdAt], ); return (
{!compact &&

{senderName}

}

{date}

); } function EmptyState({ tab }: { tab: DrawerTab }) { const Icon = tab === 'media' ? ImageIcon : tab === 'audio' ? MicIcon : FileIcon; return (

Noch keine {TAB_LABELS[tab].toLowerCase()} im geladenen Verlauf.

); } function labelFor(mimeType: string): string { if (mimeType.startsWith('audio/')) return 'Audiodatei'; if (mimeType === 'application/pdf') return 'PDF-Datei'; if (mimeType.startsWith('text/')) return 'Textdatei'; return mimeType || 'Datei'; } function formatSize(bytes: number): string { if (bytes < 1024) return bytes + ' B'; if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(0) + ' KB'; return (bytes / 1024 / 1024).toFixed(1) + ' MB'; }