import { Card, Stack, Group, Text, Badge, Button, Loader, Progress, rem, useComputedColorScheme, } from '@mantine/core'; import { Download } from 'lucide-react'; import { MouseEvent } from 'react'; import { pretifyBinName } from '@/utils/assets'; interface DownloadCardProps { name: string; size: string; version?: string; description?: string; isCurrent?: boolean; isInstalled?: boolean; isDownloading?: boolean; downloadProgress?: number; disabled?: boolean; hasUpdate?: boolean; newerVersion?: string; onDownload: (e: MouseEvent) => void; onMakeCurrent?: () => void; onUpdate?: (e: MouseEvent) => void; } export const DownloadCard = ({ name, size, version, description, isCurrent = false, isInstalled = false, isDownloading = false, downloadProgress = 0, disabled = false, hasUpdate = false, newerVersion, onDownload, onMakeCurrent, onUpdate, }: DownloadCardProps) => { const computedColorScheme = useComputedColorScheme('light', { getInitialValueInEffect: false, }); const isDark = computedColorScheme === 'dark'; const renderActionButtons = () => { const buttons = []; if (!isInstalled) { return ( ); } if (!isCurrent && onMakeCurrent) { buttons.push( ); } if (hasUpdate && onUpdate) { buttons.push( ); } return buttons.length > 0 ? {buttons} : null; }; return (
{pretifyBinName(name)} {isCurrent && ( Current )} {hasUpdate && ( Update Available )} {description && ( {description} )} {version && ( Version {version} )} {size && ( <> {size} )}
{renderActionButtons()}
{isDownloading && downloadProgress !== undefined && ( {Math.min(downloadProgress, 100) === 100 ? '100%' : `${Math.min(downloadProgress, 100).toFixed(1)}%`}{' '} complete )}
); };