import React, { useState } from 'react'; import styles from './media.module.css'; import { CommentMediaInfo } from '../../lib/utils/media-utils'; import useFetchGifFirstFrame from '../../hooks/use-fetch-gif-first-frame'; import Embed from '../embed'; import { useTranslation } from 'react-i18next'; interface MediaProps { commentMediaInfo?: CommentMediaInfo; isMobile: boolean; isReply: boolean; linkHeight?: number; linkWidth?: number; showThumbnail: boolean; setShowThumbnail: (showThumbnail: boolean) => void; toggleExpanded?: () => void; } interface ThumbnailProps { style: React.CSSProperties; children: React.ReactNode; thumbnailSmallPadding?: string; } const ThumbnailBig = ({ style, children }: ThumbnailProps) => ( {children} ); const ThumbnailSmall = ({ style, children, thumbnailSmallPadding }: ThumbnailProps) => ( {children} ); const Thumbnail = ({ commentMediaInfo, isMobile, isReply, linkHeight, linkWidth }: MediaProps) => { let displayWidth, displayHeight; const maxThumbnailSize = isMobile || isReply ? 125 : 250; if (linkWidth && linkHeight) { let scale = Math.min(1, maxThumbnailSize / Math.max(linkWidth, linkHeight)); displayWidth = `${linkWidth * scale}px`; displayHeight = `${linkHeight * scale}px`; } else { displayWidth = `${maxThumbnailSize}px`; displayHeight = `${maxThumbnailSize}px`; } let mediaComponent: React.ReactNode = null; const iframeThumbnail = commentMediaInfo?.patternThumbnailUrl || commentMediaInfo?.thumbnail; const gifFrameUrl = useFetchGifFirstFrame(commentMediaInfo?.type === 'gif' ? commentMediaInfo.url : undefined); if (commentMediaInfo?.type === 'image') { mediaComponent = ; } else if (commentMediaInfo?.type === 'video') { mediaComponent = commentMediaInfo.thumbnail ? :