import React from 'react'; import { View, Text, ScrollView } from 'react-native'; import { useAppTheme } from '@theme'; import { WalletIcon } from '@icons'; import { useAppSelector } from '@store'; import { formatCurrency } from '@utils/formatters'; import { getStyles } from './earningsScreen.styles'; export const EarningsScreen: React.FC = () => { const { colors } = useAppTheme(); const styles = getStyles(colors); const { todayEarnings, completedCount, onlineMinutes } = useAppSelector((state) => state.earnings); const { jobHistory } = useAppSelector((state) => state.job); // Default mock jobs history if none completed yet const defaultHistory: { orderId: string; time: string; amount: number; paymentType: 'online' | 'cod'; }[] = [ { orderId: '#ORD125487', time: '12:35 PM', amount: 78.0, paymentType: 'online' }, { orderId: '#ORD125422', time: '11:15 AM', amount: 65.0, paymentType: 'cod' }, { orderId: '#ORD125389', time: '09:40 AM', amount: 120.0, paymentType: 'online' }, { orderId: '#ORD125310', time: 'Yesterday', amount: 85.0, paymentType: 'online' }, ]; const displayHistory = jobHistory.length > 0 ? jobHistory.map(job => ({ orderId: job.orderId, time: job.deliveredAt ? new Date(job.deliveredAt).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'}) : 'Delivered', amount: job.amount, paymentType: job.paymentType, })).concat(defaultHistory) : defaultHistory; const formatOnlineTime = (mins: number) => { const hours = Math.floor(mins / 60); const remainingMins = mins % 60; return `${hours}h ${remainingMins < 10 ? `0${remainingMins}` : remainingMins}m`; }; return ( Earnings {/* Total Earnings Card */} Today's Earnings {formatCurrency(todayEarnings)} {completedCount} Deliveries {formatOnlineTime(onlineMinutes)} Online Time ₹78.50 Avg / Order {/* Recent Deliveries List */} Recent Deliveries {displayHistory.map((item, index) => ( {item.orderId} {item.time} +{formatCurrency(item.amount)} {item.paymentType.toUpperCase()} ))} ); }; export default EarningsScreen;