import { useState, useEffect } from 'react' import { View, Text, StyleSheet, TextInput, Pressable, StatusBar as RNStatusBar, ActivityIndicator, } from 'react-native' import { StatusBar } from 'expo-status-bar' import { SafeAreaView } from 'react-native-safe-area-context' import { useRouter, useLocalSearchParams } from 'expo-router' import { LeftArrowIcon, CloseIcon } from '@/components/icon' import SearchResultsGrid from '@/components/SearchResultsGrid' import { useTemplates } from '@/hooks/data/use-templates' export default function SearchResultsScreen() { const router = useRouter() const params = useLocalSearchParams() const [searchText, setSearchText] = useState((params.q as string) || '') const { execute, data, loading } = useTemplates() useEffect(() => { if (searchText) { execute({ search: searchText }) } }, [searchText]) const searchResults = data?.templates.map((template) => ({ id: parseInt(template.id), title: template.title, image: { uri: template.coverImageUrl }, height: template.aspectRatio === '9:16' ? 236 : 131, videoUrl: template.previewUrl, thumbnailUrl: template.coverImageUrl, })) || [] return ( {/* Top Bar with Search */} router.back()} > { router.push({ pathname: '/searchTemplate', params: { q: searchText, focus: 'true' }, }) }} > {searchText.length > 0 && ( { e.stopPropagation() router.push({ pathname: '/searchTemplate', params: { q: '', focus: 'true' }, }) }} style={styles.clearButton} > )} 搜索 {/* 搜索结果网格 */} {loading ? ( ) : searchResults.length === 0 ? ( 未找到相关模板 尝试使用其他关键词搜索 ) : ( )} ) } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#090A0B', }, topBar: { height: 44, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 12, marginTop: 8, marginBottom: 12, }, searchInputContainer: { flex: 1, marginLeft: 4, marginRight: 12, position: 'relative', height: 40, }, searchInput: { flex: 1, color: '#F5F5F5', fontSize: 14, height: 40, paddingVertical: 8, paddingLeft: 12, paddingRight: 36, borderWidth: 0, borderColor: 'transparent', borderRadius: 100, backgroundColor: '#16181B', }, clearButton: { position: 'absolute', right: 8, top: 0, bottom: 0, justifyContent: 'center', alignItems: 'center', padding: 4, }, searchButton: { paddingHorizontal: 0, paddingVertical: 8, }, searchButtonText: { color: '#F5F5F5', fontSize: 14, fontWeight: '500', }, loadingContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', }, emptyContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', paddingHorizontal: 24, }, emptyText: { color: '#F5F5F5', fontSize: 16, fontWeight: '500', marginBottom: 8, }, emptySubText: { color: '#ABABAB', fontSize: 14, fontWeight: '400', }, })