import { JSX, MouseEvent } from 'react'; import { Icon } from './Icon'; import { DownloadProgress } from './DownloadProgress'; import { Game, InstallStatus } from '../lib/types'; import { actionLabel, primaryActionFor, PrimaryAction } from '../lib/gameState'; interface Props { game: Game; size?: 'md' | 'lg'; full?: boolean; onClick: () => void; onCancelDownload?: (game: Game) => void; } const ICON_FOR_ACTION: Partial> = { play: , install: , update: , download: , }; /** Color-coded primary action: Play / Install / Update / Download / busy. */ export const ActionButton = ({ game, size = 'md', full = false, onClick, onCancelDownload, }: Props) => { const action = primaryActionFor(game); const isDownloading = game.install_status === InstallStatus.Downloading; if (isDownloading) { return ( ); } const cls = [ 'act-btn', `act-${action}`, size === 'lg' ? 'act-lg' : '', full ? 'act-full' : '', ].filter(Boolean).join(' '); const disabled = action === 'busy' || action === 'disabled'; const handle = (e: MouseEvent) => { e.stopPropagation(); if (disabled) return; onClick(); }; return ( ); };