import { useState } from 'react'; import { View, Text, StyleSheet, Alert, KeyboardAvoidingView, Platform, ScrollView } from 'react-native'; import { useRouter } from 'expo-router'; import { Ionicons } from '@expo/vector-icons'; import { useAuthStore } from '@/lib/auth-store'; import { getApiError } from '@/lib/api'; import { Colors } from '@/lib/colors'; import { FontSize, FontWeight, IconSize, Radius, Spacing } from '@/lib/theme'; import { AppBar, Button, Card, TextField } from '@/components/ui'; export default function LoginScreen() { const router = useRouter(); const { login } = useAuthStore(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleLogin = async () => { setError(null); if (!email || !password) { setError('Veuillez remplir tous les champs.'); return; } setLoading(true); try { await login(email, password); router.replace('/(tabs)'); } catch (err) { const message = getApiError(err).message || 'Identifiants incorrects'; setError(message); Alert.alert('Erreur', message); } finally { setLoading(false); } }; return ( Bienvenue sur CESIZen Votre compagnon de santé mentale. {error ? ( {error} ) : null} { setEmail(v); setError(null); }} placeholder="votre@email.com" keyboardType="email-address" autoCapitalize="none" autoComplete="email" required /> { setPassword(v); setError(null); }} placeholder="Votre mot de passe" secureTextEntry autoComplete="password" required />