import { BasketballScoreTable } from "@/components/match-detail/basketball/basketball-score-table"; import { CardsCard } from "@/components/match-detail/football/cards-card"; import { FootballScoreTable } from "@/components/match-detail/football/football-score-table"; import { GoalsCard } from "@/components/match-detail/football/goals-card"; import { LineupsCard } from "@/components/match-detail/football/lineups-card"; import { SubstitutesCard } from "@/components/match-detail/football/substitutes-card"; import { LeagueInfo } from "@/components/match-detail/league-info"; import { MatchInfoCard } from "@/components/match-detail/match-info-card"; import { MatchTabs } from "@/components/match-detail/match-tabs"; import { OddsView } from "@/components/match-detail/odds/odds-view"; import { ScoreHeader } from "@/components/match-detail/score-header"; import { ThemedText } from "@/components/themed-text"; import { ThemedView } from "@/components/themed-view"; import { Colors } from "@/constants/theme"; import { useTheme } from "@/context/ThemeContext"; import { fetchMatchDetail } from "@/lib/api"; import { MatchDetailData } from "@/types/api"; import { useLocalSearchParams, useRouter } from "expo-router"; import React, { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { ActivityIndicator, ScrollView, StyleSheet, TouchableOpacity, View, } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; export default function MatchDetailScreen() { const { id } = useLocalSearchParams<{ id: string }>(); const router = useRouter(); const { theme } = useTheme(); const { t } = useTranslation(); const insets = useSafeAreaInsets(); const isDark = theme === "dark"; const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [data, setData] = useState(null); const [activeTab, setActiveTab] = useState("info"); useEffect(() => { if (id) { loadMatchDetail(); } }, [id]); // 当数据加载完成且 sportId 变化时,检查并重置 activeTab useEffect(() => { if (data?.match?.sportId) { const sportId = data.match.sportId; let validTabs: string[] = []; if (sportId === 1) { // 足球 validTabs = ["info", "stats", "odds", "h2h", "chat"]; } else if (sportId === 2) { // 篮球 validTabs = ["info", "h2h", "chat"]; } else { // 默认 validTabs = ["info", "h2h", "chat"]; } // 如果当前 activeTab 不在有效标签列表中,重置为第一个 if (!validTabs.includes(activeTab)) { setActiveTab(validTabs[0]); } } }, [data?.match?.sportId]); const loadMatchDetail = async () => { try { setLoading(true); setError(null); const result = await fetchMatchDetail(id as string); setData(result); console.log("首发阵容" , result.match.players?.away_team); console.log("红黄牌", result.events); } catch (err: any) { setError(err.message || t("detail.fetch_failed")); } finally { setLoading(false); } }; if (loading) { return ( ); } if (error || !data) { return ( {error || t("detail.not_found")} {t("detail.retry")} ); } const renderTabContent = () => { const sportId = data?.match?.sportId || 1; switch (activeTab) { case "info": // 根据 sportId 显示不同的详情组件 if (sportId === 1) { // 足球:显示 FootballScoreTable (半场/全场) 和 MatchInfoCard return ( <> ); } else if (sportId === 2) { // 篮球:显示 BasketballScoreTable (4节) 和 MatchInfoCard return ( <> ); } else { // 默认使用足球组件 return ( <> ); } case "stats": // 统计数据:显示进球、红黄牌、换人、首发阵容(分开显示) if (sportId === 1) { // 足球:分别显示各个卡片 return ( <> ); } else { // 其他运动暂时显示空状态 return ( {t("detail.empty_stats")} ); } case "odds": return ; case "h2h": return ( {t("detail.empty_h2h")} ); case "chat": return ( {t("detail.empty_chat")} ); default: return null; } }; return ( {renderTabContent()} ); } const styles = StyleSheet.create({ container: { flex: 1, }, center: { flex: 1, justifyContent: "center", alignItems: "center", padding: 20, }, errorText: { fontSize: 16, marginBottom: 20, textAlign: "center", }, retryButton: { paddingHorizontal: 20, paddingVertical: 10, backgroundColor: "#007AFF", borderRadius: 8, }, retryText: { color: "#FFF", fontWeight: "600", }, emptyContent: { padding: 50, alignItems: "center", }, emptyText: { opacity: 0.5, }, });