import { useEffect } from 'react'; import { ActivityIndicator, Pressable, StyleSheet, Text, TextInput, View, } from 'react-native'; import { Image } from 'expo-image'; import { useAuthSession } from '@/providers/AuthProvider'; import { useProfile } from '@/features/profile/hooks/useProfile'; import { useUpdateProfile } from '@/features/profile/hooks/useUpdateProfile'; import { router } from 'expo-router'; import { StatusMessage } from '@/shared/ui/StatusMessage'; export default function ProfileScreen() { const { logout } = useAuthSession(); const { profile, loading, error, reload } = useProfile(); const { displayName, photoURL, setPhotoURL, setDisplayName, isSubmitting, error: updateError, successMessage, submit, } = useUpdateProfile(profile?.displayName ?? '', profile?.photoURL ?? ''); useEffect(() => { if (profile?.displayName) { setDisplayName(profile.displayName); } setPhotoURL(profile?.photoURL ?? ''); }, [profile?.displayName, profile?.photoURL, setDisplayName, setPhotoURL]); const handleLogout = async () => { await logout(); router.replace('/(auth)/welcome'); }; if (loading) { return ( ); } if (error || !profile) { return ( {error ?? 'No se pudo cargar el perfil'} Reintentar ); } return ( Perfil {photoURL ? ( ) : ( {displayName.trim().charAt(0).toUpperCase() || 'U'} )} Correo {profile.email} Nombre URL de la foto {updateError ? : null} {successMessage ? : null} {isSubmitting ? 'Guardando...' : 'Guardar cambios'} Cerrar sesión ); } const styles = StyleSheet.create({ container: { flex: 1, padding: 16, gap: 16, }, center: { flex: 1, alignItems: 'center', justifyContent: 'center', padding: 24, gap: 12, }, title: { fontSize: 28, fontWeight: '700', }, card: { borderWidth: 1, borderColor: '#ddd', borderRadius: 12, padding: 16, gap: 10, }, avatarSection: { alignItems: 'center', gap: 12, marginBottom: 8, }, avatar: { width: 112, height: 112, borderRadius: 56, backgroundColor: '#ddd', }, avatarPlaceholder: { alignItems: 'center', justifyContent: 'center', backgroundColor: '#1f6feb', }, avatarPlaceholderText: { color: '#fff', fontSize: 36, fontWeight: '700', }, label: { fontSize: 14, fontWeight: '700', color: '#444', }, value: { fontSize: 16, color: '#111', }, input: { borderWidth: 1, borderColor: '#ccc', borderRadius: 10, paddingHorizontal: 14, paddingVertical: 12, }, button: { backgroundColor: '#1f6feb', paddingVertical: 14, borderRadius: 10, alignItems: 'center', }, logoutButton: { backgroundColor: '#c62828', paddingVertical: 14, borderRadius: 10, alignItems: 'center', }, buttonText: { color: '#fff', fontWeight: '600', }, error: { color: '#9f1d35', textAlign: 'center', }, });