import { memo, useState, } from 'react' import { RiDeleteBinLine, RiDownloadLine, RiEyeLine, } from '@remixicon/react' import FileTypeIcon from '../file-type-icon' import { downloadFile, fileIsUploaded, getFileAppearanceType, getFileExtension, } from '../utils' import FileImageRender from '../file-image-render' import type { FileEntity } from '../types' import ActionButton from '@/app/components/base/action-button' import ProgressCircle from '@/app/components/base/progress-bar/progress-circle' import { formatFileSize } from '@/utils/format' import cn from '@/utils/classnames' import { ReplayLine } from '@/app/components/base/icons/src/vender/other' import { SupportUploadFileTypes } from '@/app/components/workflow/types' import ImagePreview from '@/app/components/base/image-uploader/image-preview' type FileInAttachmentItemProps = { file: FileEntity showDeleteAction?: boolean showDownloadAction?: boolean onRemove?: (fileId: string) => void onReUpload?: (fileId: string) => void canPreview?: boolean } const FileInAttachmentItem = ({ file, showDeleteAction, showDownloadAction = true, onRemove, onReUpload, canPreview, }: FileInAttachmentItemProps) => { const { id, name, type, progress, supportFileType, base64Url, url, isRemote } = file const ext = getFileExtension(name, type, isRemote) const isImageFile = supportFileType === SupportUploadFileTypes.image const [imagePreviewUrl, setImagePreviewUrl] = useState('') return ( <>
{ isImageFile && ( ) } { !isImageFile && ( ) }
{name}
{ ext && ( {ext.toLowerCase()} ) } { ext && ( ) } { !!file.size && ( {formatFileSize(file.size)} ) }
{ progress >= 0 && !fileIsUploaded(file) && ( ) } { progress === -1 && ( onReUpload?.(id)} > ) } { showDeleteAction && ( onRemove?.(id)}> ) } { canPreview && isImageFile && ( setImagePreviewUrl(url || '')}> ) } { showDownloadAction && ( { e.stopPropagation() downloadFile(url || base64Url || '', name) }}> ) }
{ imagePreviewUrl && canPreview && ( setImagePreviewUrl('')} /> ) } ) } export default memo(FileInAttachmentItem)