import { useState, type ReactNode } from "react"; import { View, Text, TextInput, TouchableOpacity, StyleSheet, Alert, ActivityIndicator, KeyboardAvoidingView, Platform, } from "react-native"; import { useAuth } from "../context/AuthContext"; import { isValidEmail } from "@cloud-reader/shared"; export default function LoginScreen({ navigation }: { navigation: any }): ReactNode { const { state, login, clearError } = useAuth(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const handleLogin = async () => { clearError(); if (!email.trim()) { Alert.alert("Validation Error", "Please enter your email."); return; } if (!isValidEmail(email.trim())) { Alert.alert("Validation Error", "Please enter a valid email address."); return; } if (!password) { Alert.alert("Validation Error", "Please enter your password."); return; } try { await login(email.trim(), password); } catch { // Error handled in context } }; return ( Cloud Reader Sign in to your account {state.error && ( {state.error} )} {state.isLoading ? ( ) : ( Sign In )} navigation.navigate("Register")}> Don't have an account?{" "} Sign Up ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#0f0f23", }, inner: { flex: 1, justifyContent: "center", paddingHorizontal: 24, }, title: { fontSize: 32, fontWeight: "bold", color: "#fff", textAlign: "center", marginBottom: 8, }, subtitle: { fontSize: 16, color: "#888", textAlign: "center", marginBottom: 32, }, input: { backgroundColor: "#1a1a2e", borderRadius: 8, padding: 16, fontSize: 16, color: "#fff", marginBottom: 12, borderWidth: 1, borderColor: "#333", }, button: { backgroundColor: "#4f8ef7", borderRadius: 8, padding: 16, alignItems: "center", marginTop: 8, marginBottom: 24, }, buttonDisabled: { opacity: 0.6, }, buttonText: { color: "#fff", fontSize: 16, fontWeight: "600", }, errorBox: { backgroundColor: "rgba(255, 69, 58, 0.15)", borderRadius: 8, padding: 12, marginBottom: 16, borderWidth: 1, borderColor: "rgba(255, 69, 58, 0.3)", }, errorText: { color: "#ff453a", fontSize: 14, textAlign: "center", }, linkText: { color: "#888", textAlign: "center", fontSize: 14, }, linkBold: { color: "#4f8ef7", fontWeight: "600", }, });