import { LayoutAnimation, Platform, Pressable, Text, UIManager, View, } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { useTranslation } from 'react-i18next'; import { useMailResults, type MailBlockedItem } from '../../hooks/useMailResults'; if (Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental) { UIManager.setLayoutAnimationEnabledExperimental(true); } type Props = { expanded: boolean; onToggle: () => void; }; function formatDate(iso: string, t: (k: string) => string): string { const diff = Date.now() - new Date(iso).getTime(); const mins = Math.floor(diff / 60_000); if (mins < 2) return t('mail.account_just_now'); if (mins < 60) return `${mins} min`; const hours = Math.floor(mins / 60); if (hours < 24) return `${hours}h`; return `${Math.floor(hours / 24)}d`; } export function MailActivityLog({ expanded, onToggle }: Props) { const { t } = useTranslation(); const { results, total, loading, refresh } = useMailResults(expanded); function handleToggle() { LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); onToggle(); } return ( {t('mail.activity_log_title')} {t('mail.activity_log_subtitle')} {expanded && ( {loading && results.length === 0 ? ( {t('mail.loading')} ) : results.length === 0 ? ( {t('mail.activity_log_empty')} ) : ( <> {results.slice(0, 10).map((item) => ( ))} {total > 10 ? t('mail.activity_log_more', { count: total - 10 }) : t('mail.activity_log_count', { count: total })} )} )} ); } function ActivityItem({ item, t, }: { item: MailBlockedItem; t: (k: string, opts?: any) => string; }) { return ( {item.subject || t('mail.activity_no_subject')} {item.sender_name || item.sender_email} {formatDate(item.received_at, t)} ); }