import { Box, CircularProgress, Typography, useTheme, Button } from '@mui/material'; import InputHeader from '../InputHeader'; import greyPattern from '@assets/grey-pattern.png'; import { globalInputHeight } from '../../config/uiConfig'; import ResultFooter from './ResultFooter'; import { useTranslation } from 'react-i18next'; import React, { useContext } from 'react'; import { CustomSnackBarContext } from '../../contexts/CustomSnackBarContext'; export default function ToolMultiFileResult({ title = 'Result', value, zipFile, loading, loadingText }: { title?: string; value: File[]; zipFile?: File | null; loading?: boolean; loadingText?: string; }) { const { t } = useTranslation(); const theme = useTheme(); const { showSnackBar } = useContext(CustomSnackBarContext); const getFileType = ( file: File ): 'image' | 'video' | 'audio' | 'pdf' | 'unknown' => { if (file.type.startsWith('image/')) return 'image'; if (file.type.startsWith('video/')) return 'video'; if (file.type.startsWith('audio/')) return 'audio'; if (file.type.startsWith('application/pdf')) return 'pdf'; return 'unknown'; }; const handleDownload = (file: File) => { const url = URL.createObjectURL(file); const a = document.createElement('a'); a.href = url; a.download = file.name; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }; const handleCopy = () => { if (zipFile) { const blob = new Blob([zipFile], { type: zipFile.type }); const clipboardItem = new ClipboardItem({ [zipFile.type]: blob }); navigator.clipboard .write([clipboardItem]) .then(() => showSnackBar(t('toolMultiFileResult.copied'), 'success')) .catch((err) => { showSnackBar( t('toolMultiFileResult.copyFailed', { error: err }), 'error' ); }); } }; return ( {loading ? ( {loadingText || t('toolMultiFileResult.loading')} ) : ( value.length > 0 && value.map((file, idx) => { const preview = URL.createObjectURL(file); const fileType = getFileType(file); return ( {fileType === 'image' && ( {`Preview )} {fileType === 'video' && (