import {ActivityIndicator, Pressable, TextStyle, View, ViewStyle} from "react-native" import {Icon, Text} from "@/components/ignite" import GlassView from "@/components/ui/GlassView" import {Group} from "@/components/ui/Group" import {useAppTheme} from "@/contexts/ThemeContext" import {STTModelManager} from "@mentra/engine-host-internal" import {ThemedStyle} from "@/theme" export type LanguageRow = { code: string displayName: string size: number downloaded: boolean } type LanguageSelectorProps = { title: string languages: LanguageRow[] currentLanguage: string downloadingLanguage?: string downloadPercent?: number extractionPercent?: number onPickLanguage: (code: string) => void formatBytes?: (bytes: number) => string /** * For a model with no "in use" choice (e.g. the wake-word model): downloaded * rows show this hint instead of "In use" / "Tap to use", without a check. */ downloadedHint?: string } export default function LanguageSelector({ title, languages, currentLanguage, downloadingLanguage, downloadPercent, extractionPercent, onPickLanguage, formatBytes = STTModelManager.formatBytes, downloadedHint, }: LanguageSelectorProps) { const {theme, themed} = useAppTheme() return ( {languages.map((lang) => { const isActive = downloadedHint === undefined && lang.code === currentLanguage && lang.downloaded const isDownloading = lang.code === downloadingLanguage let subtitle: string if (isDownloading) { if (extractionPercent !== undefined && extractionPercent > 0) { subtitle = extractionPercent >= 100 ? "Finishing up…" : `Extracting… ${extractionPercent}%` } else if (downloadPercent !== undefined && downloadPercent > 0) { subtitle = `Downloading… ${downloadPercent}%` } else { subtitle = "Preparing download…" } } else if (lang.downloaded && downloadedHint !== undefined) { subtitle = `${formatBytes(lang.size)} · ${downloadedHint}` } else if (lang.downloaded) { subtitle = isActive ? `${formatBytes(lang.size)} · In use` : `${formatBytes(lang.size)} · Tap to use` } else { subtitle = `${formatBytes(lang.size)} · Tap to download` } return ( onPickLanguage(lang.code)}> {isDownloading ? ( ) : isActive ? ( ) : lang.downloaded ? null : ( )} ) })} ) } const $row: ThemedStyle = ({spacing}) => ({ flexDirection: "row", alignItems: "center", paddingVertical: spacing.s4, paddingHorizontal: spacing.s4, }) const $rowText: ThemedStyle = () => ({ flex: 1, }) const $rowIcon: ThemedStyle = ({spacing}) => ({ marginLeft: spacing.s3, alignItems: "center", justifyContent: "center", minWidth: 24, }) const $rowTitle: ThemedStyle = ({colors}) => ({ fontSize: 16, fontWeight: "600", color: colors.text, }) const $rowSubtitle: ThemedStyle = ({colors}) => ({ fontSize: 13, marginTop: 2, color: colors.textDim, })