import React from 'react'; import { DownloadIcon } from '../components/icons'; import { AUDIO_EXTENSIONS, VIDEO_EXTENSIONS } from '../constants/preview'; interface MediaViewerProps { src: string; mimeType?: string; filename?: string; alt?: string; className?: string; style?: React.CSSProperties; onLoad?: (event: React.SyntheticEvent) => void; onClick?: (event: React.MouseEvent) => void; mediaRef?: React.Ref; draggable?: boolean; } const getFileExtension = (filename?: string | null) => { if (!filename) { return ''; } const match = filename.toLowerCase().match(/\.([a-z0-9]+)$/); return match ? match[1] : ''; }; const MediaViewer: React.FC = ({ src, mimeType = '', filename = '', alt = 'Media preview', className, style, onLoad, onClick, mediaRef, draggable = false, }) => { const normalizedMimeType = mimeType.toLowerCase(); const fileExtension = getFileExtension(filename); const isImage = normalizedMimeType.startsWith('image/'); const isAudio = normalizedMimeType.startsWith('audio/') || AUDIO_EXTENSIONS.has(fileExtension); const isVideo = normalizedMimeType.startsWith('video/') || VIDEO_EXTENSIONS.has(fileExtension); const viewerClasses = ['document-viewer__object', className].filter(Boolean).join(' '); if (isImage) { return ( {alt} ); } if (isAudio) { return (