import { View, Text, StyleSheet, FlatList, RefreshControl, TouchableOpacity, ActivityIndicator, Platform, useWindowDimensions } from "react-native"; import { useMatchStore, useAuthStore } from "../../src/store"; import { useEffect, useCallback } from "react"; import { useFocusEffect } from "expo-router"; import { Ionicons } from "@expo/vector-icons"; import { useRouter } from "expo-router"; import { LinearGradient } from "expo-linear-gradient"; import Animated, { FadeInDown, FadeInRight } from "react-native-reanimated"; import { GradientBackground, GlassCard } from "../../src/components/ui"; import { colors, gradients, spacing, typography, radius, shadows } from "../../src/theme"; const MAX_CONTENT_WIDTH = 500; export default function MatchesScreen() { const { matches, fetchMatches, markAllAsSeen } = useMatchStore(); const { user } = useAuthStore(); const router = useRouter(); const { width } = useWindowDimensions(); const isWideScreen = width > MAX_CONTENT_WIDTH; useFocusEffect( useCallback(() => { fetchMatches(); }, []) ); useEffect(() => { if (matches.length > 0) { markAllAsSeen(); } }, [matches.length]); const renderItem = ({ item, index }: { item: any; index: number }) => { const userResponse = item.responses?.find((r: any) => r.user_id === user?.id); const partnerResponse = item.responses?.find((r: any) => r.user_id !== user?.id); let userText = item.question.text; let partnerText = item.question.partner_text; if (item.question.partner_text && userResponse && partnerResponse) { const userTime = new Date(userResponse.created_at).getTime(); const partnerTime = new Date(partnerResponse.created_at).getTime(); if (userTime > partnerTime) { userText = item.question.partner_text; partnerText = item.question.text; } } const isYesYes = item.match_type === "yes_yes"; return ( router.push(`/chat/${item.id}`)} activeOpacity={0.8} > {userText} {item.question.partner_text && ( Partner: {partnerText} )} {isYesYes ? "YES + YES" : "YES + MAYBE"} {new Date(item.created_at).toLocaleDateString()} {item.unreadCount > 0 && ( )} ); }; if (!user) { return ( ); } return ( Matches {matches.length} Discover what you both enjoy together item.id} contentContainerStyle={[styles.list, isWideScreen && styles.listWide]} showsVerticalScrollIndicator={false} refreshControl={ } ListEmptyComponent={ No matches yet Keep swiping to find things you both enjoy! router.push("/(app)/swipe")} activeOpacity={0.8} > Start Swiping } /> ); } const styles = StyleSheet.create({ container: { flex: 1, }, loadingContainer: { flex: 1, justifyContent: "center", alignItems: "center", }, header: { paddingTop: 60, paddingHorizontal: spacing.lg, paddingBottom: spacing.lg, }, headerWide: { alignSelf: 'center', width: '100%', maxWidth: MAX_CONTENT_WIDTH, }, headerTop: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', }, title: { ...typography.title1, color: colors.text, }, countBadge: { flexDirection: 'row', alignItems: 'center', backgroundColor: colors.primaryLight, paddingHorizontal: spacing.sm, paddingVertical: spacing.xs, borderRadius: radius.full, gap: spacing.xs, }, countText: { ...typography.subhead, color: colors.text, fontWeight: '600', }, subtitle: { ...typography.subhead, color: colors.textSecondary, marginTop: spacing.xs, }, list: { padding: spacing.lg, paddingTop: 0, paddingBottom: Platform.OS === 'ios' ? 120 : 100, }, listWide: { alignSelf: 'center', width: '100%', maxWidth: MAX_CONTENT_WIDTH, }, matchCard: { marginBottom: spacing.sm, }, matchRow: { flexDirection: "row", alignItems: "center", }, iconContainer: { width: 48, height: 48, borderRadius: 24, justifyContent: "center", alignItems: "center", marginRight: spacing.md, }, content: { flex: 1, }, questionText: { ...typography.body, color: colors.text, fontWeight: "600", marginBottom: spacing.xs, lineHeight: 22, }, partnerText: { ...typography.caption1, color: colors.textSecondary, fontStyle: "italic", marginBottom: spacing.sm, }, metaRow: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", }, tag: { backgroundColor: colors.glass.background, paddingHorizontal: spacing.sm, paddingVertical: 4, borderRadius: radius.sm, }, tagHighlight: { backgroundColor: colors.primaryLight, }, tagText: { ...typography.caption2, color: colors.textSecondary, fontWeight: "700", letterSpacing: 0.5, }, tagTextHighlight: { color: colors.primary, }, date: { ...typography.caption2, color: colors.textTertiary, }, rightSection: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, marginLeft: spacing.sm, }, unreadBadge: { width: 24, height: 24, borderRadius: 12, backgroundColor: colors.primary, justifyContent: 'center', alignItems: 'center', }, chevronContainer: { width: 28, height: 28, borderRadius: 14, backgroundColor: colors.glass.background, justifyContent: 'center', alignItems: 'center', }, emptyContainer: { alignItems: "center", paddingVertical: spacing.xxl, paddingHorizontal: spacing.lg, }, emptyIconGradient: { width: 100, height: 100, borderRadius: 50, justifyContent: 'center', alignItems: 'center', marginBottom: spacing.lg, ...shadows.lg, }, emptyIconInner: { width: 88, height: 88, borderRadius: 44, backgroundColor: colors.background, justifyContent: 'center', alignItems: 'center', }, emptyTitle: { ...typography.title2, color: colors.text, marginBottom: spacing.sm, }, emptyText: { ...typography.body, color: colors.textSecondary, textAlign: "center", marginBottom: spacing.xl, }, emptyButton: { borderRadius: radius.full, overflow: 'hidden', ...shadows.md, }, emptyButtonGradient: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: spacing.lg, paddingVertical: spacing.md, gap: spacing.sm, }, emptyButtonText: { ...typography.body, color: colors.text, fontWeight: '600', }, });