import React, { memo, useMemo } from 'react'; import { StyleSheet, Text, View, } from 'react-native'; import Ionicons from '@react-native-vector-icons/ionicons'; import type { TransactionRecord } from '../../types/app'; import { useTheme } from '../../theme'; import { formatCurrency, formatDate } from '../../utils/formatters'; interface TransactionItemProps { item: TransactionRecord; } type RiskLevel = 'safe' | 'medium' | 'high'; const TransactionItemComponent = ({ item }: TransactionItemProps) => { const theme = useTheme(); const isCredit = item.direction === 'credit'; const riskLevel = useMemo(() => { const sum = item.id.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0); if (sum % 10 < 7) return 'safe'; if (sum % 10 < 9) return 'medium'; return 'high'; }, [item.id]); const riskConfig = { safe: { color: theme.colors.success, label: 'SECURE', icon: 'shield-checkmark' as const }, medium: { color: theme.colors.warning, label: 'FLAGGED', icon: 'warning' as const }, high: { color: theme.colors.danger, label: 'HIGH RISK', icon: 'alert-circle' as const }, }[riskLevel]; return ( {item.title} {item.counterparty} {formatDate(item.occurredAt)} {isCredit ? '+' : '-'} {formatCurrency(item.amount)} {riskConfig.label} ); }; const styles = StyleSheet.create({ wrapper: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingVertical: 18, borderBottomWidth: 1, }, leading: { flexDirection: 'row', alignItems: 'center', gap: 16, flex: 1, }, icon: { width: 46, height: 46, borderRadius: 23, alignItems: 'center', justifyContent: 'center', borderWidth: 1, }, copy: { gap: 4, flex: 1, }, titleRow: { flexDirection: 'row', alignItems: 'center', }, title: { fontSize: 16, fontWeight: '800', letterSpacing: -0.3, }, subtitleRow: { flexDirection: 'row', alignItems: 'center', gap: 6, }, dot: { width: 3, height: 3, borderRadius: 1.5, backgroundColor: 'rgba(255, 255, 255, 0.2)', }, subtitle: { fontSize: 12, fontWeight: '500', }, trailing: { alignItems: 'flex-end', gap: 4, }, amount: { fontSize: 16, fontWeight: '800', letterSpacing: -0.2, }, riskBadge: { paddingHorizontal: 6, paddingVertical: 2, borderRadius: 6, borderWidth: 1, }, riskText: { fontSize: 8, fontWeight: '900', letterSpacing: 0.5, }, }); export const TransactionItem = memo(TransactionItemComponent);