import React from 'react'; import { StyleSheet, FlatList } from 'react-native'; import { View, Text, useTheme } from '@bettoredge/styles'; import { Ionicons } from '@expo/vector-icons'; import type { CalcuttaAuctionItemProps, CalcuttaItemResultProps } from '@bettoredge/types'; import { formatCurrency, getStatusLabel } from '../helpers/formatting'; export interface CalcuttaItemResultsProps { item: CalcuttaAuctionItemProps; item_results: CalcuttaItemResultProps[]; market_type: string; } export const CalcuttaItemResults: React.FC = ({ item, item_results, market_type, }) => { const { theme } = useTheme(); const results = [...item_results] .filter(r => r.calcutta_auction_item_id === item.calcutta_auction_item_id) .sort((a, b) => (a.round_number ?? 0) - (b.round_number ?? 0)); const totalPayout = results.reduce((sum, r) => sum + Number(r.payout_earned), 0); const getResultIcon = (result: string): { name: keyof typeof Ionicons.glyphMap; color: string } => { switch (result) { case 'advanced': return { name: 'checkmark-circle', color: theme.colors.status.success }; case 'eliminated': return { name: 'close-circle', color: theme.colors.status.error }; case 'won': return { name: 'trophy', color: '#FFD700' }; case 'placed': return { name: 'medal-outline', color: theme.colors.primary.default }; default: return { name: 'ellipse-outline', color: theme.colors.text.tertiary }; } }; const renderResult = ({ item: result }: { item: CalcuttaItemResultProps }) => { const icon = getResultIcon(result.result); return ( R{result.round_number ?? '-'} {getStatusLabel(result.result)} {result.placement != null && ( Placement: {result.placement} )} {result.payout_earned > 0 ? ( +{formatCurrency(result.payout_earned, market_type)} ) : ( - )} {result.processed && ( )} ); }; return ( {/* Item header */} {item.item_name} {item.seed != null ? `#${item.seed} Seed` : item.item_type} {' \u00B7 '} {getStatusLabel(item.status)} Won for {item.winning_bid > 0 ? formatCurrency(item.winning_bid, market_type) : '-'} {/* Summary */} Rounds {results.length} Advanced {results.filter(r => r.result === 'advanced' || r.result === 'won').length} Total Payout 0 ? theme.colors.status.success : theme.colors.text.primary }}> {formatCurrency(totalPayout, market_type)} {/* Results list */} r.calcutta_item_result_id} renderItem={renderResult} ListEmptyComponent={ No results yet } /> ); }; const styles = StyleSheet.create({ container: { flex: 1, }, header: { flexDirection: 'row', alignItems: 'center', padding: 12, borderBottomWidth: 1, }, headerLeft: { flex: 1, flexDirection: 'row', alignItems: 'center', }, itemIcon: { width: 36, height: 36, borderRadius: 18, alignItems: 'center', justifyContent: 'center', }, headerInfo: { flex: 1, marginLeft: 10, }, headerRight: { alignItems: 'flex-end', marginLeft: 10, }, summary: { flexDirection: 'row', paddingVertical: 10, paddingHorizontal: 12, borderBottomWidth: 1, }, summaryItem: { flex: 1, alignItems: 'center', }, resultRow: { flexDirection: 'row', alignItems: 'center', paddingVertical: 10, paddingHorizontal: 12, borderBottomWidth: 1, }, roundCol: { width: 30, }, resultIcon: { marginRight: 8, }, resultInfo: { flex: 1, }, payoutCol: { alignItems: 'flex-end', marginLeft: 10, }, emptyText: { textAlign: 'center', padding: 20, }, });