import { formatBytes } from '~/lib/util' import { useTranslation } from 'react-i18next' 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, }) => { const { t } = useTranslation() // 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 */}

{t('contentExplorer.wikipedia.title')}

{t('contentExplorer.wikipedia.selectPackage')}

{/* Downloading status message */} {isDownloading && (
{t('contentExplorer.wikipedia.downloading')}
)} {/* 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 && ( {t('contentExplorer.wikipedia.installed')} )} {isPending && !isInstalled && ( {t('contentExplorer.wikipedia.selected')} )} {isCurrentDownloading && ( {t('contentExplorer.wikipedia.downloadingBadge')} )} {isCurrentFailed && ( Failed )}
{/* Option content */}

{option.name}

{option.description}

{/* Radio indicator */}
{isSelected && }
{option.size_mb === 0 ? t('contentExplorer.wikipedia.noDownload') : formatBytes(option.size_mb * 1024 * 1024, 1)}
) })}
{/* Submit button for Content Explorer mode */} {showSubmitButton && selectedOptionId && (selectedOptionId !== currentSelection?.optionId || isFailed) && (
{selectedOptionId === 'none' ? t('contentExplorer.wikipedia.removeWikipedia') : t('contentExplorer.wikipedia.downloadSelected')}
)}
) } export default WikipediaSelector