import { ThemedText } from "@/components/themed-text"; import { IconSymbol } from "@/components/ui/icon-symbol"; import { addFavorite, checkFavorite, removeFavorite } from "@/lib/api"; import { MatchDetailData } from "@/types/api"; import { LinearGradient } from "expo-linear-gradient"; import { useRouter } from "expo-router"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { Image, StyleSheet, TouchableOpacity, View } from "react-native"; interface ScoreHeaderProps { data: MatchDetailData; isDark: boolean; topInset: number; } export function ScoreHeader({ data, isDark, topInset }: ScoreHeaderProps) { const router = useRouter(); const { t } = useTranslation(); const { match } = data; const [isFav, setIsFav] = useState(false); const [favLoading, setFavLoading] = useState(false); // 检查收藏状态 React.useEffect(() => { const loadFavStatus = async () => { try { const res = await checkFavorite("match", match.eventKey.toString()); setIsFav(res.isFavorite); } catch (error) { console.error("Check favorite status error:", error); } }; if (match.eventKey) { loadFavStatus(); } }, [match.eventKey]); const toggleFavorite = async () => { if (favLoading) return; setFavLoading(true); const newFavState = !isFav; try { if (newFavState) { await addFavorite({ matchId: Number(match.eventKey), type: "match", typeId: match.eventKey.toString(), notify: true, }); } else { await removeFavorite({ type: "match", typeId: match.eventKey.toString(), }); } setIsFav(newFavState); } catch (error) { console.error("Toggle favorite error:", error); } finally { setFavLoading(false); } }; return ( {/* Top Bar */} router.back()} style={styles.iconBtn} > {match.eventStatus || t("detail.pending")} {/* Score Section */} {match.eventHomeTeam} {match.eventFinalResult && match.eventFinalResult !== "-" ? match.eventFinalResult : "0-0"} {match.eventAwayTeam} ); } const styles = StyleSheet.create({ container: { paddingBottom: 24, paddingHorizontal: 16, }, topBar: { flexDirection: "row", alignItems: "center", marginBottom: 16, minHeight: 44, }, leftContainer: { flex: 1, flexDirection: "row", alignItems: "center", }, statusContainer: { flex: 2, justifyContent: "center", alignItems: "center", }, rightContainer: { flex: 1, flexDirection: "row", justifyContent: "flex-end", alignItems: "center", gap: 4, }, statusText: { color: "#FFF", fontSize: 17, fontWeight: "600", opacity: 0.9, }, iconBtn: { width: 40, height: 40, justifyContent: "center", alignItems: "center", borderRadius: 20, backgroundColor: "rgba(255,255,255,0.1)", marginHorizontal: 4, }, scoreRow: { flexDirection: "row", alignItems: "flex-start", justifyContent: "space-between", paddingHorizontal: 0, marginTop: 10, }, teamInfo: { flex: 1, alignItems: "center", }, logoContainer: { width: 70, height: 70, marginBottom: 10, justifyContent: "center", alignItems: "center", }, teamLogo: { width: 60, height: 60, resizeMode: "contain", }, teamName: { color: "#FFF", fontSize: 14, fontWeight: "700", textAlign: "center", lineHeight: 18, }, centerScore: { flex: 1.4, alignItems: "center", paddingTop: 8, }, scoreBox: { backgroundColor: "#FFF", borderRadius: 16, paddingHorizontal: 24, paddingVertical: 12, marginBottom: 16, minWidth: 100, alignItems: "center", shadowColor: "#000", shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.2, shadowRadius: 4, elevation: 4, }, scoreValue: { color: "#000", fontSize: 30, fontWeight: "700", lineHeight: 30, letterSpacing: 1, }, fieldBtn: { backgroundColor: "#0044FF", width: 60, height: 32, borderRadius: 16, justifyContent: "center", alignItems: "center", borderWidth: 1, borderColor: "rgba(255,255,255,0.2)", }, });