import { useState } from "react"; import { Card, Stack, Text, Group, Badge, Button, Box, Image, ThemeIcon, ActionIcon, Tooltip } from "@mantine/core"; import { useTranslation } from "react-i18next"; import PictureAsPdfIcon from "@mui/icons-material/PictureAsPdf"; import StorageIcon from "@mui/icons-material/Storage"; import VisibilityIcon from "@mui/icons-material/Visibility"; import EditIcon from "@mui/icons-material/Edit"; import PushPinIcon from "@mui/icons-material/PushPin"; import PushPinOutlinedIcon from "@mui/icons-material/PushPinOutlined"; import { FileWithUrl } from "../../types/file"; import { getFileSize, getFileDate } from "../../utils/fileUtils"; import { useIndexedDBThumbnail } from "../../hooks/useIndexedDBThumbnail"; import { useFileContext } from "../../contexts/FileContext"; interface FileCardProps { file: FileWithUrl; onRemove: () => void; onDoubleClick?: () => void; onView?: () => void; onEdit?: () => void; isSelected?: boolean; onSelect?: () => void; isSupported?: boolean; // Whether the file format is supported by the current tool } const FileCard = ({ file, onRemove, onDoubleClick, onView, onEdit, isSelected, onSelect, isSupported = true }: FileCardProps) => { const { t } = useTranslation(); const { thumbnail: thumb, isGenerating } = useIndexedDBThumbnail(file); const [isHovered, setIsHovered] = useState(false); const { pinFile, unpinFile, isFilePinned } = useFileContext(); const isPinned = isFilePinned(file as File); return ( setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} onClick={onSelect} data-testid="file-card" > {/* Pin indicator - always visible when pinned */} {isPinned && (
)} {/* Hover action buttons */} {isHovered && (onView || onEdit || true) && (
e.stopPropagation()} > {/* Pin/Unpin button */} { e.stopPropagation(); if (isPinned) { unpinFile(file as File); } else { pinFile(file as File); } }} > {isPinned ? : } {onView && ( { e.stopPropagation(); onView(); }} > )} {onEdit && ( { e.stopPropagation(); onEdit(); }} > )}
)} {thumb ? ( PDF thumbnail ) : isGenerating ? (
Generating...
) : (
100 * 1024 * 1024 ? "orange" : "red"} size={60} radius="sm" style={{ display: "flex", alignItems: "center", justifyContent: "center" }} > {file.size > 100 * 1024 * 1024 && ( Large File )}
)} {file.name} {getFileSize(file)} {getFileDate(file)} {file.storedInIndexedDB && ( } > DB )} {!isSupported && ( {t("fileManager.unsupported", "Unsupported")} )} ); }; export default FileCard;