import React, { useEffect, useRef } from 'react'; import { StyleSheet, TouchableOpacity, Animated, Dimensions, FlatList } from 'react-native'; import { View, Text, useTheme } from '@bettoredge/styles'; import { Ionicons } from '@expo/vector-icons'; import type { CalcuttaAuctionItemProps } from '@bettoredge/types'; import { formatCurrency } from '../../helpers/formatting'; interface AuctionResultsModalProps { visible: boolean; onDismiss: () => void; wonItems: CalcuttaAuctionItemProps[]; market_type: string; } const SCREEN_HEIGHT = Dimensions.get('window').height; export const AuctionResultsModal: React.FC = ({ visible, onDismiss, wonItems, market_type, }) => { const { theme } = useTheme(); const scaleAnim = useRef(new Animated.Value(0.8)).current; const opacityAnim = useRef(new Animated.Value(0)).current; useEffect(() => { if (visible) { Animated.parallel([ Animated.spring(scaleAnim, { toValue: 1, friction: 6, tension: 40, useNativeDriver: true, }), Animated.timing(opacityAnim, { toValue: 1, duration: 300, useNativeDriver: true, }), ]).start(); } else { scaleAnim.setValue(0.8); opacityAnim.setValue(0); } }, [visible]); if (!visible) return null; const totalSpent = wonItems.reduce((s, i) => s + Number(i.winning_bid), 0); const hasWins = wonItems.length > 0; return ( {/* Header */} {hasWins ? ( <> Congratulations! You won {wonItems.length} item{wonItems.length !== 1 ? 's' : ''} for {formatCurrency(totalSpent, market_type)} ) : ( <> Auction Complete You didn't win any items this time. Better luck next auction! )} {/* Won items list */} {hasWins && ( {wonItems.slice(0, 6).map(item => ( {item.item_name} {formatCurrency(item.winning_bid, market_type)} ))} {wonItems.length > 6 && ( +{wonItems.length - 6} more item{wonItems.length - 6 !== 1 ? 's' : ''} )} )} {/* CTA */} {hasWins ? 'View My Items' : 'View Results'} ); }; const styles = StyleSheet.create({ overlay: { backgroundColor: 'rgba(0,0,0,0.6)', alignItems: 'center', justifyContent: 'center', padding: 24, }, modal: { width: '100%', maxWidth: 360, borderRadius: 16, padding: 24, alignItems: 'center', }, header: { alignItems: 'center', marginBottom: 20, }, itemsList: { width: '100%', marginBottom: 20, gap: 8, }, wonItem: { flexDirection: 'row', alignItems: 'center', padding: 10, borderRadius: 8, }, ctaButton: { width: '100%', paddingVertical: 14, borderRadius: 10, alignItems: 'center', }, });