import { Card, Stack, Group, Text, Badge, Button, Loader, Progress, rem, } from '@mantine/core'; import { Download, Trash2 } from 'lucide-react'; import { MouseEvent } from 'react'; import { pretifyBinName, isWindowsROCmBuild } from '@/utils/assets'; import { usePreferencesStore } from '@/stores/preferences'; import { useKoboldVersionsStore } from '@/stores/koboldVersions'; import type { VersionInfo } from '@/types'; interface DownloadCardProps { version: VersionInfo; size: string; description?: string; disabled?: boolean; onDownload: (e: MouseEvent) => void; onMakeCurrent?: () => void; onUpdate?: (e: MouseEvent) => void; onRedownload?: (e: MouseEvent) => void; onDelete?: (e: MouseEvent) => void; } export const DownloadCard = ({ version: versionInfo, size, description, disabled = false, onDownload, onMakeCurrent, onUpdate, onRedownload, onDelete, }: DownloadCardProps) => { const { resolvedColorScheme: colorScheme } = usePreferencesStore(); const { downloading, downloadProgress } = useKoboldVersionsStore(); const isLoading = downloading === versionInfo.name; const currentProgress = isLoading ? Math.min(downloadProgress[versionInfo.name], 100) || 0 : 0; const hasVersionMismatch = Boolean( versionInfo.version && versionInfo.actualVersion && versionInfo.version !== versionInfo.actualVersion ); // eslint-disable-next-line sonarjs/cognitive-complexity const renderActionButtons = () => { const buttons = []; if (!versionInfo.isInstalled) { return ( ); } if (!versionInfo.isCurrent && onMakeCurrent) { buttons.push( ); } if (versionInfo.hasUpdate && onUpdate) { buttons.push( ); } if (hasVersionMismatch && onRedownload) { buttons.push( ); } if (onDelete && versionInfo.isInstalled && !versionInfo.isCurrent) { buttons.push( ); } return buttons.length > 0 ? {buttons} : null; }; return (
{pretifyBinName(versionInfo.name)} {versionInfo.isCurrent && ( Current )} {versionInfo.hasUpdate && ( Update Available )} {isWindowsROCmBuild(versionInfo.name) && ( Experimental )} {description && ( {description} )} {versionInfo.version && ( Version {versionInfo.version} {hasVersionMismatch && versionInfo.actualVersion && ( {' '} (actual: {versionInfo.actualVersion}) )} )} {size && ( <> {size} )}
{renderActionButtons()}
{isLoading && currentProgress !== undefined && ( {currentProgress === 100 ? '100.0% complete' : `${currentProgress.toFixed(1).padStart(5, ' ')}% complete`} )}
); };