import { View, Text, Switch, TouchableOpacity, ActivityIndicator } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { useTranslation } from 'react-i18next'; import type { ProtectionState } from '../../lib/protection'; import { useColors } from '../../lib/theme'; type Props = { state: ProtectionState; loading: boolean; /** Aktiviert den Schutz. UI sollte missingLayers den User durchsteppen lassen. */ onActivate: () => Promise; /** Click 1 of 3 — öffnet ProtectionDetailsSheet. KEIN direktes deactivate! */ onPressSettings: () => void; }; export function ProtectionCard({ state, loading, onActivate, onPressSettings }: Props) { const { t } = useTranslation(); const colors = useColors(); const isActive = state.phase === 'active' || state.phase === 'cooldownActive'; const isCooldown = state.phase === 'cooldownActive'; const subtitle = (() => { if (state.phase === 'inactive') return t('blocker.protection_subtitle_inactive'); if (state.phase === 'cooldownActive') return t('blocker.protection_subtitle_cooldown'); if (state.plan === 'free') { return t('blocker.protection_subtitle_free', { count: state.blocklistCount }); } if (state.plan === 'legend') { return t('blocker.protection_subtitle_legend'); } return t('blocker.protection_subtitle_pro'); })(); const cardBg = isCooldown ? '#fef3c7' : isActive ? '#dcfce7' : colors.bg; const cardBorder = isCooldown ? '#fcd34d' : isActive ? '#86efac' : colors.border; const iconBg = isCooldown ? '#fde68a' : isActive ? '#bbf7d0' : '#f5f5f5'; const iconColor = isCooldown ? '#d97706' : isActive ? '#16a34a' : '#a3a3a3'; return ( {t('blocker.protection_card_title')} {subtitle} {/* Loading: Spinner. Inactive: Switch zum aktivieren. Active: Settings-Icon */} {loading ? ( ) : isActive ? ( ) : ( { if (v) onActivate(); }} trackColor={{ true: '#16a34a' }} /> )} {/* Stats-Row nur wenn aktiv und kein Cooldown */} {state.phase === 'active' && ( )} ); } function Stat({ label, value, valueColor, }: { label: string; value: string; valueColor?: string; }) { const colors = useColors(); return ( {value} {label} ); } function formatCount(n: number): string { if (n >= 1000) return `${Math.floor(n / 1000)}k+`; return String(n); }