import { Card, Flex, Typography, Button, Tag, Divider } from 'antd'
import PropTypes from 'prop-types'
import FileIcon from '../../Icons/FileIcon'
import BinIcon from '../../Icons/BinIcon'
import EyeIcon from '../../Icons/EyeIcon'
import DownloadIcon from '../../Icons/DownloadIcon'
import { useContext, useState } from 'react'
import { ApiServerContext } from '../context/ApiServerContext'
import FilePreview from './FilePreview'
import EyeSlashIcon from '../../Icons/EyeSlashIcon'
import { getModelByName } from '../../../database/ObjectModels'
import InfoCircleIcon from '../../Icons/InfoCircleIcon'
import { useNavigate } from 'react-router-dom'
const { Text } = Typography
const FileList = ({
files,
onChange,
multiple = true,
editing = false,
showPreview = true,
showInfo = true,
showDownload = true,
defaultPreviewOpen = false,
card = true
}) => {
const { fetchFileContent, flushFile } = useContext(ApiServerContext)
const navigate = useNavigate()
const [previewOpen, setPreviewOpen] = useState(defaultPreviewOpen)
const infoAction = getModelByName('file').actions.filter(
(action) => action.name == 'info'
)[0]
// Check if there are no items in the list
const hasNoItems = multiple
? !files || !Array.isArray(files) || files.length === 0
: !files
if (hasNoItems) {
return null
}
const handleRemove = (fileToRemove) => {
flushFile(fileToRemove._id)
if (multiple) {
const currentFiles = Array.isArray(files) ? files : []
const updatedFiles = currentFiles.filter((file) => {
const fileUid = file._id || file.id
const removeUid = fileToRemove._id || fileToRemove.id
return fileUid !== removeUid
})
onChange(updatedFiles)
} else {
onChange(null)
}
}
const handleDownload = async (file) => {
await fetchFileContent(file, true)
}
const filesToRender = multiple ? files : [files]
const renderFileContent = (file) => (