import {useState} from "react" import { View, TouchableOpacity, Modal, FlatList, Pressable, KeyboardAvoidingView, Platform, TouchableWithoutFeedback, ActivityIndicator, ViewStyle, TextStyle, } from "react-native" import {Icon, Text, Button} from "@/components/ignite" import {Group} from "@/components/ui/Group" import {useAppTheme} from "@/contexts/ThemeContext" import {STTModelManager} from "@mentra/engine-host-internal" import {ThemedStyle} from "@/theme" type SelectableModelInfo = { name: string size: number downloaded: boolean modelId: string } type ModelSelectorProps = { selectedModelId: string models: SelectableModelInfo[] onModelChange: (modelId: string) => void onDownload: (modelId: string) => void onDelete: (modelId: string) => void isDownloading: boolean downloadProgress: number extractionProgress: number currentModelInfo: SelectableModelInfo | null title?: string downloadButtonText?: string formatBytes?: (bytes: number) => string } const ModelSelector: React.FC = ({ selectedModelId, models, onModelChange, onDownload, onDelete: _onDelete, isDownloading, downloadProgress, extractionProgress, currentModelInfo: _currentModelInfo, title = "Offline Mode Speech Model", downloadButtonText = "Download Model", formatBytes = STTModelManager.formatBytes, }) => { const {theme, themed} = useAppTheme() const [modalVisible, setModalVisible] = useState(false) const selectedModel = models.find((m) => m.modelId === selectedModelId) const isDownloaded = selectedModel?.downloaded || false const getStatusIcon = () => { if (isDownloading) { return } return null } const getSubtitle = () => { if (!selectedModel) return "" if (isDownloading) { if (extractionProgress > 0) { return `Extracting...` } else if (downloadProgress > 0) { return `Downloading... ${downloadProgress}%` } else { return "Preparing download..." } } const sizeText = formatBytes(selectedModel.size) if (isDownloaded) { return `${sizeText} • Downloaded` } return `${sizeText} • Not downloaded` } const renderModelOption = ({item}: {item: SelectableModelInfo}) => { const isSelected = item.modelId === selectedModelId const isModelDownloaded = item.downloaded return ( { onModelChange(item.modelId) setModalVisible(false) }}> {isSelected && } ) } return ( setModalVisible(true)} activeOpacity={0.7}> {getStatusIcon()} {/* Download button for current selection */} {selectedModel && !isDownloaded && !isDownloading && (