import React, { useState } from 'react'; import { View, Text, TextInput, TouchableOpacity, StyleSheet, Alert, KeyboardAvoidingView, Platform, ActivityIndicator, } from 'react-native'; import { useAuth } from '../contexts/AuthContext'; export function LoginScreen({ navigation }: any) { const { login } = useAuth(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); async function handleLogin() { if (!username.trim() || !password) { Alert.alert('Erreur', 'Veuillez remplir tous les champs'); return; } setLoading(true); try { await login(username.trim(), password); } catch (error: any) { Alert.alert('Erreur', error.message || 'Connexion échouée'); } finally { setLoading(false); } } return ( Dot. Connectez-vous à votre compte {loading ? ( ) : ( Se connecter )} navigation.navigate('Register')} disabled={loading} > Pas de compte ? S'inscrire ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', }, inner: { flex: 1, justifyContent: 'center', paddingHorizontal: 32, }, title: { fontSize: 32, fontWeight: 'bold', textAlign: 'center', marginBottom: 8, }, subtitle: { fontSize: 16, color: '#666', textAlign: 'center', marginBottom: 32, }, input: { borderWidth: 1, borderColor: '#ddd', borderRadius: 8, padding: 16, fontSize: 16, marginBottom: 16, }, button: { backgroundColor: '#000', borderRadius: 8, padding: 16, alignItems: 'center', marginBottom: 16, }, buttonDisabled: { opacity: 0.6, }, buttonText: { color: '#fff', fontSize: 16, fontWeight: '600', }, linkButton: { alignItems: 'center', }, linkText: { color: '#000', fontSize: 14, }, });