import { useEffect, useState } from 'react'; import { View, Text, FlatList, TouchableOpacity, StyleSheet, RefreshControl, ActivityIndicator, Image, } from 'react-native'; import { useNavigation } from '@react-navigation/native'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { championshipsApi } from '../../api/championships'; import type { Championship } from '../../types'; import type { AppStackParams } from '../../navigation'; const STATUS_COLOR: Record = { open: '#16a34a', draft: '#9ca3af', closed: '#dc2626', completed: '#2563eb', }; function StatusBadge({ status }: { status: string }) { return ( {status.toUpperCase()} ); } function ChampionshipCard({ item, onPress }: { item: Championship; onPress: () => void }) { return ( {item.image_url && ( )} {item.title} {item.location && 📍 {item.location}} {item.event_date && ( 📅 {new Date(item.event_date).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric' })} )} {item.entry_fee != null && ( 💰 Entry fee: {item.entry_fee} BYN )} ); } export default function ChampionshipsScreen() { const navigation = useNavigation>(); const [championships, setChampionships] = useState([]); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); const [error, setError] = useState(null); const load = async (silent = false) => { if (!silent) setLoading(true); setError(null); try { const data = await championshipsApi.list(); setChampionships(data); } catch { setError('Failed to load championships'); } finally { setLoading(false); setRefreshing(false); } }; useEffect(() => { load(); }, []); if (loading) { return ( ); } return ( item.id} contentContainerStyle={styles.list} ListEmptyComponent={ {error ?? 'No championships yet'} } renderItem={({ item }) => ( navigation.navigate('ChampionshipDetail', { id: item.id })} /> )} refreshControl={ { setRefreshing(true); load(true); }} /> } /> ); } const styles = StyleSheet.create({ list: { padding: 16 }, heading: { fontSize: 24, fontWeight: '700', color: '#1a1a2e', marginBottom: 16 }, center: { flex: 1, justifyContent: 'center', alignItems: 'center', paddingTop: 60 }, empty: { color: '#9ca3af', fontSize: 15 }, card: { backgroundColor: '#fff', borderRadius: 14, marginBottom: 14, overflow: 'hidden', shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.08, shadowRadius: 6, elevation: 3, }, cardImage: { width: '100%', height: 160 }, cardBody: { padding: 14 }, cardHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 8 }, cardTitle: { flex: 1, fontSize: 17, fontWeight: '600', color: '#1a1a2e', marginRight: 8 }, badge: { paddingHorizontal: 8, paddingVertical: 3, borderRadius: 6 }, badgeText: { color: '#fff', fontSize: 11, fontWeight: '700' }, cardMeta: { fontSize: 13, color: '#555', marginTop: 4 }, });