import { RiCloseLine, RiDownloadLine, } from '@remixicon/react' import { downloadFile, fileIsUploaded, getFileAppearanceType, getFileExtension, } from '../utils' import FileTypeIcon from '../file-type-icon' import type { FileEntity } from '../types' import cn from '@/utils/classnames' import { formatFileSize } from '@/utils/format' import ProgressCircle from '@/app/components/base/progress-bar/progress-circle' import { ReplayLine } from '@/app/components/base/icons/src/vender/other' import ActionButton from '@/app/components/base/action-button' import Button from '@/app/components/base/button' type FileItemProps = { file: FileEntity showDeleteAction?: boolean showDownloadAction?: boolean onRemove?: (fileId: string) => void onReUpload?: (fileId: string) => void } const FileItem = ({ file, showDeleteAction, showDownloadAction = true, onRemove, onReUpload, }: FileItemProps) => { const { id, name, type, progress, url, isRemote } = file const ext = getFileExtension(name, type, isRemote) const uploadError = progress === -1 return (
{ showDeleteAction && ( ) }
{name}
{ ext && ( <> {ext}
ยท
) } { !!file.size && formatFileSize(file.size) }
{ showDownloadAction && ( { e.stopPropagation() downloadFile(url || '', name) }} > ) } { progress >= 0 && !fileIsUploaded(file) && ( ) } { uploadError && ( onReUpload?.(id)} /> ) }
) } export default FileItem