import React from 'react'; import { StyleSheet, FlatList, Image } from 'react-native'; import { View, Text, useTheme } from '@bettoredge/styles'; import { Ionicons } from '@expo/vector-icons'; import type { CalcuttaParticipantProps, PublicPlayerProps } from '@bettoredge/types'; import { formatCurrency, formatPlace } from '../helpers/formatting'; export interface CalcuttaLeaderboardProps { participants: CalcuttaParticipantProps[]; players?: Record; player_id?: string; market_type: string; listHeader?: React.ReactNode; } export const CalcuttaLeaderboard: React.FC = ({ participants, players, player_id, market_type, listHeader, }) => { const { theme } = useTheme(); const sorted = [...participants].sort((a, b) => { if (a.place && b.place) return a.place - b.place; if (a.place) return -1; if (b.place) return 1; return b.total_winnings - a.total_winnings; }); const renderHeader = () => ( <>{listHeader} # Player Items Spent Won ); const renderItem = ({ item, index }: { item: CalcuttaParticipantProps; index: number }) => { const place = item.place ?? index + 1; const isPositive = item.total_winnings > item.total_spent; const isMe = item.player_id === player_id; const player = players?.[item.player_id]; const username = player?.username || player?.show_name || `Player ${item.player_id.slice(0, 6)}`; const profilePic = player?.profile_pic; return ( {place <= 3 ? ( ) : ( {formatPlace(place)} )} {profilePic ? ( ) : ( {username.charAt(0).toUpperCase()} )} {username} {isMe && ( YOU )} {item.items_owned} {formatCurrency(item.total_spent, market_type)} {formatCurrency(item.total_winnings, market_type)} ); }; return ( item.calcutta_participant_id} ListHeaderComponent={renderHeader} renderItem={renderItem} ListEmptyComponent={ No participants yet } /> ); }; const styles = StyleSheet.create({ headerRow: { flexDirection: 'row', alignItems: 'center', paddingVertical: 8, paddingHorizontal: 12, borderBottomWidth: 1, }, row: { flexDirection: 'row', alignItems: 'center', paddingVertical: 10, paddingHorizontal: 12, borderBottomWidth: 1, }, placeCol: { width: 32, alignItems: 'center', }, playerInfo: { flex: 1, flexDirection: 'row', alignItems: 'center', marginLeft: 4, }, playerCol: { flex: 1, marginLeft: 4, }, avatar: { width: 28, height: 28, borderRadius: 14, alignItems: 'center', justifyContent: 'center', overflow: 'hidden', }, youBadge: { paddingHorizontal: 5, paddingVertical: 1, borderRadius: 4, marginLeft: 4, }, numCol: { width: 60, textAlign: 'right', }, emptyText: { textAlign: 'center', padding: 20, }, });