import { formatBytes } from '~/lib/util' import { WikipediaOption, WikipediaCurrentSelection } from '../../types/downloads' import classNames from 'classnames' import { IconCheck, IconDownload, IconWorld, IconAlertTriangle } from '@tabler/icons-react' import StyledButton from './StyledButton' import LoadingSpinner from './LoadingSpinner' export interface WikipediaSelectorProps { options: WikipediaOption[] currentSelection: WikipediaCurrentSelection | null selectedOptionId: string | null // for wizard (pending selection) onSelect: (optionId: string) => void disabled?: boolean showSubmitButton?: boolean // true for Content Explorer, false for wizard onSubmit?: () => void isSubmitting?: boolean } const WikipediaSelector: React.FC = ({ options, currentSelection, selectedOptionId, onSelect, disabled = false, showSubmitButton = false, onSubmit, isSubmitting = false, }) => { // Determine which option to highlight const highlightedOptionId = selectedOptionId ?? currentSelection?.optionId ?? null // Check if current selection is downloading or failed const isDownloading = currentSelection?.status === 'downloading' const isFailed = currentSelection?.status === 'failed' return (
{/* Header with Wikipedia branding */}

Wikipedia

Select your preferred Wikipedia package

{/* Downloading status message */} {isDownloading && (
Downloading Wikipedia... This may take a while for larger packages.
)} {/* Failed status message */} {isFailed && (
Wikipedia download failed. Select a package and try again.
)} {/* Options grid */}
{options.map((option) => { const isSelected = highlightedOptionId === option.id const isInstalled = currentSelection?.optionId === option.id && currentSelection?.status === 'installed' const isCurrentDownloading = currentSelection?.optionId === option.id && currentSelection?.status === 'downloading' const isCurrentFailed = currentSelection?.optionId === option.id && currentSelection?.status === 'failed' const isPending = selectedOptionId === option.id && selectedOptionId !== currentSelection?.optionId return (
!disabled && !isCurrentDownloading && onSelect(option.id)} className={classNames( 'relative p-4 rounded-lg border-2 transition-all', disabled || isCurrentDownloading ? 'opacity-60 cursor-not-allowed' : 'cursor-pointer hover:shadow-md', isInstalled ? 'border-desert-green bg-desert-green/10' : isSelected ? 'border-lime-500 bg-lime-50' : 'border-border-subtle bg-surface-primary hover:border-border-default' )} > {/* Status badges */}
{isInstalled && ( Installed )} {isPending && !isInstalled && ( Selected )} {isCurrentDownloading && ( Downloading )} {isCurrentFailed && ( Failed )}
{/* Option content */}

{option.name}

{option.description}

{/* Radio indicator */}
{isSelected && }
{option.size_mb === 0 ? 'No download' : formatBytes(option.size_mb * 1024 * 1024, 1)}
) })}
{/* Submit button for Content Explorer mode */} {showSubmitButton && selectedOptionId && (selectedOptionId !== currentSelection?.optionId || isFailed) && (
{selectedOptionId === 'none' ? 'Remove Wikipedia' : 'Download Selected'}
)}
) } export default WikipediaSelector