import React, { useState } from 'react'; import { View, Text, StyleSheet, ScrollView, Switch, TouchableOpacity, Alert, TextInput, Modal, } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { SafeAreaView } from 'react-native-safe-area-context'; import { router } from 'expo-router'; import { useAuth } from '@/contexts/AuthContext'; import { AppColors, BorderRadius, FontSizes, Spacing } from '@/constants/theme'; import { PageHeader } from '@/components/PageHeader'; interface SecurityItemProps { icon: keyof typeof Ionicons.glyphMap; iconColor: string; iconBgColor: string; title: string; description: string; onPress: () => void; rightElement?: React.ReactNode; } function SecurityItem({ icon, iconColor, iconBgColor, title, description, onPress, rightElement, }: SecurityItemProps) { return ( {title} {description} {rightElement || } ); } export default function PrivacyScreen() { const { logout } = useAuth(); const [twoFactor, setTwoFactor] = useState(false); const [biometric, setBiometric] = useState(false); const [showPasswordModal, setShowPasswordModal] = useState(false); const [currentPassword, setCurrentPassword] = useState(''); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const handleChangePassword = () => { setShowPasswordModal(true); }; const handlePasswordSubmit = () => { if (!currentPassword || !newPassword || !confirmPassword) { Alert.alert('Error', 'Please fill in all fields'); return; } if (newPassword !== confirmPassword) { Alert.alert('Error', 'New passwords do not match'); return; } if (newPassword.length < 8) { Alert.alert('Error', 'Password must be at least 8 characters'); return; } setShowPasswordModal(false); setCurrentPassword(''); setNewPassword(''); setConfirmPassword(''); Alert.alert('Success', 'Your password has been changed successfully.'); }; const handleEnable2FA = (value: boolean) => { if (value) { Alert.alert( 'Enable Two-Factor Authentication', 'This will add an extra layer of security to your account. You will need to enter a code from your authenticator app when signing in.', [ { text: 'Cancel', style: 'cancel' }, { text: 'Enable', onPress: () => { setTwoFactor(true); Alert.alert( 'Scan QR Code', 'Open your authenticator app (Google Authenticator, Authy, etc.) and scan the QR code.', [{ text: 'Done' }] ); } }, ] ); } else { Alert.alert( 'Disable Two-Factor Authentication', 'Are you sure? This will make your account less secure.', [ { text: 'Cancel', style: 'cancel' }, { text: 'Disable', style: 'destructive', onPress: () => setTwoFactor(false) }, ] ); } }; const handleManageSessions = () => { Alert.alert( 'Active Sessions', 'You are currently signed in on:\n\n' + '• iPhone 14 Pro (This device)\n Last active: Just now\n\n' + '• Chrome on MacBook Pro\n Last active: 2 hours ago\n\n' + '• Safari on iPad\n Last active: 3 days ago', [ { text: 'Close' }, { text: 'Sign Out All', style: 'destructive', onPress: () => { Alert.alert( 'Sign Out All Devices', 'This will sign you out of all devices including this one.', [ { text: 'Cancel', style: 'cancel' }, { text: 'Sign Out All', style: 'destructive', onPress: async () => { await logout(); router.replace('/(auth)/login'); } }, ] ); } }, ] ); }; const handleExportData = () => { Alert.alert( 'Export Your Data', 'We will prepare a downloadable file containing all your data. This may take a few minutes.\n\nYou will receive an email when your data is ready.', [ { text: 'Cancel', style: 'cancel' }, { text: 'Request Export', onPress: () => Alert.alert('Request Sent', 'You will receive an email when your data export is ready.') }, ] ); }; const handleDeleteAccount = () => { Alert.alert( 'Delete Account', 'Are you absolutely sure you want to delete your account?\n\n' + '• All your data will be permanently deleted\n' + '• You will lose access to all beneficiary data\n' + '• This action cannot be undone', [ { text: 'Cancel', style: 'cancel' }, { text: 'Delete Account', style: 'destructive', onPress: () => { Alert.alert( 'Final Confirmation', 'Type "DELETE" to confirm account deletion.', [{ text: 'Cancel', style: 'cancel' }] ); } }, ] ); }; return ( {/* Password & Authentication */} Authentication handleEnable2FA(!twoFactor)} rightElement={ } /> setBiometric(!biometric)} rightElement={ } /> {/* Session Management */} Sessions {/* Data & Privacy */} Data & Privacy Alert.alert('Data Sharing', 'Your data is only shared with authorized caregivers and healthcare providers you designate.')} /> {/* Login History */} Recent Activity Login from iPhone Today at 2:34 PM • San Francisco, CA Login from MacBook Yesterday at 10:15 AM • San Francisco, CA Password changed Dec 1, 2024 at 4:22 PM {/* Danger Zone */} Danger Zone Delete Account {/* Password Change Modal */} setShowPasswordModal(false)} > setShowPasswordModal(false)}> Cancel Change Password Save Current Password New Password Must be at least 8 characters Confirm New Password Password Requirements: • At least 8 characters • Mix of letters and numbers recommended • Special characters for extra security ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: AppColors.surface, }, section: { marginTop: Spacing.md, }, sectionTitle: { fontSize: FontSizes.sm, fontWeight: '600', color: AppColors.textSecondary, paddingHorizontal: Spacing.lg, paddingVertical: Spacing.sm, textTransform: 'uppercase', }, card: { backgroundColor: AppColors.background, }, securityRow: { flexDirection: 'row', alignItems: 'center', paddingVertical: Spacing.md, paddingHorizontal: Spacing.lg, }, iconContainer: { width: 40, height: 40, borderRadius: BorderRadius.md, justifyContent: 'center', alignItems: 'center', }, securityContent: { flex: 1, marginLeft: Spacing.md, }, securityTitle: { fontSize: FontSizes.base, fontWeight: '500', color: AppColors.textPrimary, }, securityDescription: { fontSize: FontSizes.xs, color: AppColors.textMuted, marginTop: 2, }, divider: { height: 1, backgroundColor: AppColors.border, marginLeft: Spacing.lg + 40 + Spacing.md, }, activityItem: { flexDirection: 'row', alignItems: 'center', paddingVertical: Spacing.md, paddingHorizontal: Spacing.lg, }, activityDot: { width: 8, height: 8, borderRadius: 4, backgroundColor: AppColors.success, marginRight: Spacing.md, }, activityDotOld: { backgroundColor: AppColors.textMuted, }, activityContent: { flex: 1, }, activityTitle: { fontSize: FontSizes.sm, fontWeight: '500', color: AppColors.textPrimary, }, activityMeta: { fontSize: FontSizes.xs, color: AppColors.textMuted, marginTop: 2, }, dangerButton: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', paddingVertical: Spacing.md, }, dangerButtonText: { fontSize: FontSizes.base, fontWeight: '500', color: AppColors.error, marginLeft: Spacing.sm, }, // Modal styles modalContainer: { flex: 1, backgroundColor: AppColors.surface, }, modalHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingHorizontal: Spacing.lg, paddingVertical: Spacing.md, backgroundColor: AppColors.background, borderBottomWidth: 1, borderBottomColor: AppColors.border, }, modalTitle: { fontSize: FontSizes.lg, fontWeight: '600', color: AppColors.textPrimary, }, cancelText: { fontSize: FontSizes.base, color: AppColors.textSecondary, }, saveText: { fontSize: FontSizes.base, fontWeight: '600', color: AppColors.primary, }, modalContent: { padding: Spacing.lg, }, inputGroup: { marginBottom: Spacing.lg, }, label: { fontSize: FontSizes.sm, fontWeight: '600', color: AppColors.textPrimary, marginBottom: Spacing.xs, }, input: { backgroundColor: AppColors.background, borderRadius: BorderRadius.md, paddingHorizontal: Spacing.md, paddingVertical: Spacing.md, fontSize: FontSizes.base, color: AppColors.textPrimary, borderWidth: 1, borderColor: AppColors.border, }, hint: { fontSize: FontSizes.xs, color: AppColors.textMuted, marginTop: Spacing.xs, }, passwordRequirements: { backgroundColor: AppColors.background, borderRadius: BorderRadius.lg, padding: Spacing.md, marginTop: Spacing.md, }, requirementsTitle: { fontSize: FontSizes.sm, fontWeight: '600', color: AppColors.textSecondary, marginBottom: Spacing.sm, }, requirementItem: { fontSize: FontSizes.sm, color: AppColors.textMuted, marginBottom: 4, }, });