import { useEffect, useState } from 'react' import { View, Text, StyleSheet, 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 } from '@/components/icon' import SearchResultsGrid from '@/components/SearchResultsGrid' import { useTemplateDetail, useTemplates } from '@/hooks/data' export default function TemplateDetailScreen() { const router = useRouter() const params = useLocalSearchParams() const templateId = params.templateId as string const { data: templateDetail, loading: detailLoading, error: detailError, execute: fetchDetail } = useTemplateDetail() const { data: relatedTemplates, loading: relatedLoading, execute: fetchRelated } = useTemplates() const [gridData, setGridData] = useState([]) useEffect(() => { if (templateId) { fetchDetail({ id: templateId }) fetchRelated({ limit: 10 }) } }, [templateId]) useEffect(() => { if (relatedTemplates?.templates) { const formattedData = relatedTemplates.templates .filter((template) => template.id !== templateId) .map((template, index) => ({ id: Number(template.id) || index, title: template.title, image: { uri: template.coverImageUrl }, height: 200, videoUrl: template.previewUrl, thumbnailUrl: template.coverImageUrl, })) setGridData(formattedData) } }, [relatedTemplates, templateId]) if (detailError) { return ( router.back()} style={styles.backButton}> 加载失败 ) } if (detailLoading) { return ( router.back()} style={styles.backButton}> ) } return ( router.back()} style={styles.backButton}> {templateDetail?.title || ''} {templateDetail?.description || ''} {relatedLoading ? ( ) : ( )} ) } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#090A0B', }, header: { flexDirection: 'row', alignItems: 'center', paddingTop: 12, paddingHorizontal: 12, paddingBottom: 24, }, backButton: { padding: 4, }, titleSection: { paddingHorizontal: 12, paddingBottom: 24, }, mainTitle: { color: '#F5F5F5', fontSize: 20, fontWeight: '500', marginBottom: 4, }, subTitle: { color: '#ABABAB', fontSize: 14, fontWeight: '400', }, loadingContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', }, errorContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', }, errorText: { color: '#ABABAB', fontSize: 16, }, })