import { Text, TouchableOpacity, View } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { useTranslation } from 'react-i18next'; import { FormSheet } from '../FormSheet'; import { useMailInterval } from '../../hooks/useMailInterval'; import type { MailAccount } from '../../hooks/useMailStatus'; type Props = { visible: boolean; account: MailAccount; localTitle: string | null; isOAuth: boolean; plan: 'free' | 'pro' | 'legend'; disconnecting?: boolean; onClose: () => void; onEditTitle: () => void; onEditPassword: () => void; onDisconnectRequest: () => void; onIntervalChanged: () => void; }; const INTERVAL_OPTIONS_BY_PLAN: Record<'free' | 'pro' | 'legend', number[]> = { free: [4], pro: [1, 4, 8], legend: [1, 4, 8], }; function domainFromEmail(email: string): string { return email.split('@')[1] ?? email; } function SettingsRow({ icon, label, value, onPress, destructive, }: { icon: React.ComponentProps['name']; label: string; value?: string; onPress?: () => void; destructive?: boolean; }) { const labelColor = destructive ? '#dc2626' : '#0a0a0a'; const Wrapper = onPress ? TouchableOpacity : View; const wrapperProps = onPress ? { activeOpacity: 0.7 as const, onPress } : {}; return ( {label} {value !== undefined && ( {value} )} {onPress && !destructive && ( )} ); } export function MailAccountSettingsSheet({ visible, account, localTitle, isOAuth, plan, disconnecting, onClose, onEditTitle, onEditPassword, onDisconnectRequest, onIntervalChanged, }: Props) { const { t } = useTranslation(); const { setInterval, updating } = useMailInterval(); const isLegend = plan === 'legend'; const intervalOptions = INTERVAL_OPTIONS_BY_PLAN[plan]; const displayTitle = localTitle ?? domainFromEmail(account.email); async function handleSetInterval(value: number) { const res = await setInterval(account.id, value); if (res.ok) onIntervalChanged(); } return ( {/* Bezeichnung */} {/* E-Mail (read-only) */} {/* Passwort — nur für IMAP-Accounts */} {!isOAuth && ( )} {/* Scan-Intervall */} {!isLegend ? ( {t('mail.scan_interval_label')} {intervalOptions.map((opt) => { const active = account.scanInterval === opt; const disabled = plan === 'free' || updating === account.id; return ( handleSetInterval(opt)} style={{ flex: 1, paddingVertical: 9, borderRadius: 10, alignItems: 'center', backgroundColor: active ? '#007AFF' : '#f5f5f5', opacity: disabled && !active ? 0.5 : 1, }} > {opt}h ); })} {plan === 'free' && ( {t('mail.free_scan_interval_hint')} )} ) : ( {t('mail.realtime_desc')} )} {/* Separator */} {/* Verbindung trennen */} {t('mail.row_disconnect')} ); }