import { formatTransferMbPerSec } from "@/main-axios.ts"; import { useTranslation } from "react-i18next"; import { ArrowDownToLine } from "lucide-react"; import { TransferProgressBar } from "./TransferProgressBar"; interface DownloadProgressToastProps { fileName: string; loaded: number; total?: number; mbPerSec?: number; } function formatBytes(bytes: number): string { if (bytes <= 0) return "0 B"; const units = ["B", "KB", "MB", "GB", "TB"]; let size = bytes; let unitIndex = 0; while (size >= 1024 && unitIndex < units.length - 1) { size /= 1024; unitIndex++; } const formattedSize = size < 10 && unitIndex > 0 ? size.toFixed(1) : Math.round(size).toString(); return `${formattedSize} ${units[unitIndex]}`; } export function DownloadProgressToast({ fileName, loaded, total, mbPerSec, }: DownloadProgressToastProps) { const { t } = useTranslation(); const percent = total !== undefined && total > 0 ? Math.min(100, Math.round((loaded / total) * 100)) : undefined; const speed = formatTransferMbPerSec(mbPerSec); return (

{t("fileManager.downloadingFile", { name: fileName })}

{total !== undefined ? t("fileManager.downloadProgressBytes", { transferred: formatBytes(loaded), total: formatBytes(total), }) : formatBytes(loaded)} {speed || "0 MB/s"}
); }