import { memo, useMemo } from '../../../lib/teact/teact';
import type { ApiAttachment } from '../../../api/types';
import { SUPPORTED_PHOTO_CONTENT_TYPES, SUPPORTED_VIDEO_CONTENT_TYPES } from '../../../config';
import buildClassName from '../../../util/buildClassName';
import { formatMediaDuration } from '../../../util/dates/dateFormat';
import { getFileExtension } from '../../common/helpers/documentInfo';
import { REM } from '../../common/helpers/mediaDimensions';
import useAppLayout from '../../../hooks/useAppLayout';
import useLastCallback from '../../../hooks/useLastCallback';
import File from '../../common/File';
import Icon from '../../common/icons/Icon';
import MediaSpoiler from '../../common/MediaSpoiler';
import styles from './AttachmentModalItem.module.scss';
type OwnProps = {
attachment: ApiAttachment;
className?: string;
shouldDisplayCompressed?: boolean;
shouldDisplayGrouped?: boolean;
isSingle?: boolean;
index: number;
onDelete?: (index: number) => void;
onToggleSpoiler?: (index: number) => void;
onEdit?: (index: number) => void;
};
const BLUR_CANVAS_SIZE = 15 * REM;
const AttachmentModalItem = ({
attachment,
className,
isSingle,
shouldDisplayCompressed,
shouldDisplayGrouped,
index,
onDelete,
onToggleSpoiler,
onEdit,
}: OwnProps) => {
const { isMobile } = useAppLayout();
const displayType = getDisplayType(attachment, shouldDisplayCompressed);
const handleSpoilerClick = useLastCallback(() => {
onToggleSpoiler?.(index);
});
const handleEditClick = useLastCallback(() => {
onEdit?.(index);
});
const content = useMemo(() => {
switch (displayType) {
case 'photo':
return (
);
case 'video':
return (
<>
{Boolean(attachment.quick?.duration) && (