import React, { useEffect } from 'react'; import { View, StyleSheet, FlatList, RefreshControl, Text } from 'react-native'; import { NativeStackScreenProps } from '@react-navigation/native-stack'; import Animated, { FadeInUp } from 'react-native-reanimated'; import { ScreenShell } from '../../../components'; import { useTheme } from '../../../theme'; import { useAppDispatch, useAppSelector } from '../../../app/hooks'; import type { AgentCollectionsStackParamList } from '../navigation/agentNavigationTypes'; import { useGetCollectionHistoryQuery } from '../services/agentApi'; import { agentActions } from '../store/agentSlice'; import { selectCollectionHistory } from '../store/agentSelectors'; import { CollectionEntryCard } from '../components/CollectionEntryCard'; import { AgentSkeletonLoader } from '../components/AgentSkeletonLoader'; import { AgentEmptyState } from '../components/AgentEmptyState'; import { formatAgentCurrency, formatDate } from '../utils/agentFormatters'; type Props = NativeStackScreenProps; export default function CollectionHistoryScreen({ navigation }: Props) { const theme = useTheme(); const dispatch = useAppDispatch(); const history = useAppSelector(selectCollectionHistory); const { data, isLoading, refetch, isFetching } = useGetCollectionHistoryQuery({}); useEffect(() => { if (data) { dispatch(agentActions.setCollectionHistory(data)); } }, [data, dispatch]); const totalCollected = history.reduce((sum, item) => sum + item.collectedAmount, 0); return ( {/* Summary Header */} Total Entries {history.length} Amount Collected {formatAgentCurrency(totalCollected)} {isLoading && history.length === 0 ? ( ) : ( item.id} contentContainerStyle={styles.listContent} showsVerticalScrollIndicator={false} refreshControl={ } ListEmptyComponent={() => ( )} renderItem={({ item, index }) => ( item.status !== 'pending' && item.receiptId ? navigation.navigate('CollectionReceipt', { entryId: item.receiptId }) : null} /> )} /> )} ); } const styles = StyleSheet.create({ summaryHeader: { flexDirection: 'row', padding: 16, borderBottomWidth: 1, }, summaryItem: { flex: 1, }, summaryLabel: { fontSize: 12, fontWeight: '500', marginBottom: 4, }, summaryValue: { fontSize: 20, fontWeight: '800', }, vDivider: { width: 1, height: '100%', marginHorizontal: 16, }, listArea: { flex: 1, }, listContent: { padding: 16, paddingBottom: 40, }, });