import { useEffect, useRef, useState } from 'react'; import { ActivityIndicator, Switch, Text, TouchableOpacity, View } from 'react-native'; import { TrueSheet, type SheetDetent } from '@lodev09/react-native-true-sheet'; import { Ionicons } from '@expo/vector-icons'; import { useTranslation } from 'react-i18next'; import { useRouter } from 'expo-router'; import { apiFetch } from '../../lib/api'; import { useColors } from '../../lib/theme'; const CONSENT_VERSION = 'art9-mail-v1-2026-05-13'; type PendingConnection = { id: string; email: string; }; type Props = { connections: PendingConnection[]; onDismiss: () => void; onConsented: () => void; }; export function MailConsentReminderSheet({ connections, onDismiss, onConsented }: Props) { const { t } = useTranslation(); const colors = useColors(); const router = useRouter(); const sheetRef = useRef(null); const [consentGiven, setConsentGiven] = useState(false); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (connections.length > 0) { sheetRef.current?.present(); } }, [connections.length]); async function handleConsent() { if (!consentGiven || submitting) return; setSubmitting(true); setError(null); try { await apiFetch('/api/mail-connections/consent', { method: 'POST', body: { mailConnectionId: connections.map((c) => c.id), consentVersion: CONSENT_VERSION, }, }); sheetRef.current?.dismiss(); onConsented(); } catch { setError(t('mail.consent.reminder_consent_error')); } finally { setSubmitting(false); } } function handleLater() { sheetRef.current?.dismiss(); onDismiss(); } function handleDisconnect() { sheetRef.current?.dismiss(); onDismiss(); router.push('/(app)/mail'); } const count = connections.length; const bodyText = count === 1 ? t('mail.consent.reminder_body_one') : t('mail.consent.reminder_body_other', { count }); return ( {t('mail.consent.reminder_title')} {bodyText} setConsentGiven((v) => !v)} style={{ flex: 1 }} > {t('mail.consent.reminder_legal_short')} {error ? ( {error} ) : null} {submitting ? ( ) : ( {t('mail.consent.reminder_cta_consent')} )} {t('mail.consent.reminder_cta_later')} {t('mail.consent.reminder_cta_disconnect')} ); }