import React, { useState } from 'react'; import { StyleSheet, TouchableOpacity, Image } from 'react-native'; import { View, Text, useTheme } from '@bettoredge/styles'; import { Ionicons } from '@expo/vector-icons'; import type { CalcuttaAuctionItemProps, CalcuttaBidProps } from '@bettoredge/types'; import type { CalcuttaLifecycleState } from '../../helpers/lifecycleState'; import { formatCurrency } from '../../helpers/formatting'; import { CalcuttaBidInput } from '../CalcuttaBidInput'; interface SealedBidItemCardProps { item: CalcuttaAuctionItemProps; my_bid?: CalcuttaBidProps; min_bid: number; bid_increment: number; escrow_balance: number; market_type: string; player_id?: string; lifecycleState: CalcuttaLifecycleState; itemImage?: { url: string }; onPlaceBid: (amount: number) => void; bidLoading: boolean; disabled?: boolean; } const QUICK_AMOUNTS = [5, 10, 25, 50]; export const SealedBidItemCard: React.FC = ({ item, my_bid, min_bid, bid_increment, escrow_balance, market_type, player_id, lifecycleState, itemImage, onPlaceBid, bidLoading, disabled, }) => { const { theme } = useTheme(); const [expanded, setExpanded] = useState(false); const hasBid = my_bid && my_bid.bid_status === 'active'; const isSold = item.status === 'sold'; const iOwnThis = isSold && item.winning_player_id === player_id; const canBidNow = lifecycleState === 'auctioning' && (item.status === 'active' || item.status === 'pending') && !disabled; // Resolve image: prefer fetched team/athlete image, fall back to stored item_image const resolvedImageUrl = itemImage?.url || item.item_image?.url; // ============================================ // PENDING / SCHEDULED — Browse mode (info only) // ============================================ if (lifecycleState === 'pending' || lifecycleState === 'scheduled') { return ( {resolvedImageUrl ? ( ) : ( )} {item.item_name} {item.seed != null && ( #{item.seed} )} {item.item_type && ( {item.item_type === 'team' ? 'Team' : 'Player'} )} ); } // ============================================ // TOURNAMENT / COMPLETED — Results view // ============================================ if (lifecycleState === 'tournament' || lifecycleState === 'completed') { const didBid = my_bid != null; return ( {resolvedImageUrl ? ( ) : iOwnThis ? ( ) : isSold ? ( ) : ( )} {item.item_name} {item.seed != null && ( #{item.seed} )} {iOwnThis && ( YOU WON )} {isSold && !iOwnThis && didBid && ( OUTBID )} {!isSold && ( Unsold )} {isSold ? ( <> {iOwnThis ? 'Paid' : 'Sold for'} {formatCurrency(item.winning_bid, market_type)} ) : ( No bids )} {didBid && isSold && !iOwnThis && ( Your bid: {formatCurrency(my_bid!.bid_amount, market_type)} )} ); } // ============================================ // AUCTIONING — Active bid UI // ============================================ return ( canBidNow && setExpanded(!expanded)} disabled={!canBidNow} > {resolvedImageUrl ? ( ) : hasBid ? ( ) : ( )} {item.item_name} {item.seed != null && ( #{item.seed} )} {item.bid_count != null && item.bid_count > 0 && ( {item.bid_count} bidder{item.bid_count !== 1 ? 's' : ''} )} {hasBid ? ( <> Your bid {formatCurrency(my_bid!.bid_amount, market_type)} ) : canBidNow ? ( Place Bid ) : ( No bid )} {canBidNow && ( )} {expanded && canBidNow && ( {QUICK_AMOUNTS.map(amt => ( onPlaceBid(amt)} disabled={bidLoading} activeOpacity={0.7} > {formatCurrency(amt, market_type)} ))} )} ); }; const styles = StyleSheet.create({ card: { borderWidth: 1, borderRadius: 10, marginHorizontal: 12, marginBottom: 8, overflow: 'hidden', }, row: { flexDirection: 'row', alignItems: 'center', padding: 12, }, iconWrap: { width: 36, height: 36, borderRadius: 18, alignItems: 'center', justifyContent: 'center', }, itemImage: { width: 36, height: 36, borderRadius: 18, }, info: { flex: 1, marginLeft: 10, }, nameRow: { flexDirection: 'row', alignItems: 'center', }, metaRow: { flexDirection: 'row', alignItems: 'center', marginTop: 2, }, wonBadge: { paddingHorizontal: 6, paddingVertical: 2, borderRadius: 4, }, bidCol: { alignItems: 'flex-end', marginLeft: 10, }, bidCta: { paddingHorizontal: 10, paddingVertical: 5, borderRadius: 6, }, lostBidRow: { paddingHorizontal: 12, paddingBottom: 10, borderTopWidth: 1, paddingTop: 8, }, expandedArea: { borderTopWidth: 1, paddingHorizontal: 12, paddingBottom: 12, }, quickRow: { flexDirection: 'row', paddingTop: 10, gap: 8, }, quickBtn: { flex: 1, paddingVertical: 8, borderRadius: 6, borderWidth: 1, alignItems: 'center', }, });