import React, { useState } from 'react'; import { View, Text, TextInput, TouchableOpacity, StyleSheet, SafeAreaView, KeyboardAvoidingView, Platform, ScrollView, StatusBar, ActivityIndicator, Image, } from 'react-native'; import { LinearGradient } from 'expo-linear-gradient'; import { useAuth } from '../contexts/AuthContext'; import { KurdistanColors } from '../theme/colors'; const AuthScreen: React.FC = () => { const { signIn, signUp } = useAuth(); // Tab state const [activeTab, setActiveTab] = useState<'signin' | 'signup'>('signin'); // Sign In state const [loginEmail, setLoginEmail] = useState(''); const [loginPassword, setLoginPassword] = useState(''); const [showLoginPassword, setShowLoginPassword] = useState(false); const [rememberMe, setRememberMe] = useState(false); // Sign Up state const [signupName, setSignupName] = useState(''); const [signupEmail, setSignupEmail] = useState(''); const [signupPassword, setSignupPassword] = useState(''); const [signupConfirmPassword, setSignupConfirmPassword] = useState(''); const [signupReferralCode, setSignupReferralCode] = useState(''); const [showSignupPassword, setShowSignupPassword] = useState(false); // Common state const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const handleSignIn = async () => { setError(''); if (!loginEmail || !loginPassword) { setError('Please fill in all fields'); return; } setLoading(true); try { const { error: signInError } = await signIn(loginEmail, loginPassword); if (signInError) { if (signInError.message?.includes('Invalid login credentials')) { setError('Email or password is incorrect'); } else { setError(signInError.message || 'Login failed'); } } } catch (err) { setError('Login failed. Please try again.'); if (__DEV__) console.error('Sign in error:', err); } finally { setLoading(false); } }; const handleSignUp = async () => { setError(''); if (!signupName || !signupEmail || !signupPassword || !signupConfirmPassword) { setError('Please fill in all required fields'); return; } if (signupPassword !== signupConfirmPassword) { setError('Passwords do not match'); return; } if (signupPassword.length < 8) { setError('Password must be at least 8 characters'); return; } setLoading(true); try { const { error: signUpError } = await signUp( signupEmail, signupPassword, signupName, signupReferralCode ); if (signUpError) { setError(signUpError.message || 'Sign up failed'); } } catch (err) { setError('Sign up failed. Please try again.'); if (__DEV__) console.error('Sign up error:', err); } finally { setLoading(false); } }; return ( {/* Grid overlay */} {/* Card Container */} {/* Header */} PezkuwiChain Access your governance account {/* Tabs */} { setActiveTab('signin'); setError(''); }} > Sign In { setActiveTab('signup'); setError(''); }} > Sign Up {/* Sign In Form */} {activeTab === 'signin' && ( Email ✉️ Password 🔒 setShowLoginPassword(!showLoginPassword)} > {showLoginPassword ? '👁️' : '👁️‍🗨️'} setRememberMe(!rememberMe)} > {rememberMe && } Remember me Forgot password? {error && ( ⚠️ {error} )} {loading ? ( ) : ( Sign In )} )} {/* Sign Up Form */} {activeTab === 'signup' && ( Full Name 👤 Email ✉️ Password 🔒 setShowSignupPassword(!showSignupPassword)} > {showSignupPassword ? '👁️' : '👁️‍🗨️'} Confirm Password 🔒 Referral Code{' '} (Optional) 👥 If someone referred you, enter their code here {error && ( ⚠️ {error} )} {loading ? ( ) : ( Create Account )} )} {/* Footer */} By continuing, you agree to our{' '} Terms of Service and Privacy Policy ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#000000', }, gradient: { flex: 1, }, gridOverlay: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, opacity: 0.1, }, keyboardView: { flex: 1, }, scrollContent: { flexGrow: 1, padding: 16, justifyContent: 'center', }, card: { backgroundColor: 'rgba(17, 24, 39, 0.9)', borderRadius: 16, padding: 24, borderWidth: 1, borderColor: 'rgba(55, 65, 81, 0.5)', }, header: { alignItems: 'center', marginBottom: 24, }, logoContainer: { width: 64, height: 64, borderRadius: 32, backgroundColor: '#FFFFFF', justifyContent: 'center', alignItems: 'center', marginBottom: 12, padding: 8, }, logoImage: { width: '100%', height: '100%', }, brandTitle: { fontSize: 24, fontWeight: 'bold', textAlign: 'center', marginBottom: 4, color: '#10B981', }, subtitle: { fontSize: 14, color: '#9CA3AF', textAlign: 'center', }, tabContainer: { flexDirection: 'row', backgroundColor: '#1F2937', borderRadius: 8, padding: 4, marginBottom: 24, }, tab: { flex: 1, paddingVertical: 8, alignItems: 'center', borderRadius: 6, }, tabActive: { backgroundColor: '#374151', }, tabText: { fontSize: 14, fontWeight: '600', color: '#9CA3AF', }, tabTextActive: { color: '#FFFFFF', }, form: { gap: 16, }, inputGroup: { marginBottom: 16, }, label: { fontSize: 14, fontWeight: '500', color: '#D1D5DB', marginBottom: 8, }, optionalText: { fontSize: 12, color: '#6B7280', }, inputContainer: { flexDirection: 'row', alignItems: 'center', backgroundColor: '#1F2937', borderRadius: 8, borderWidth: 1, borderColor: '#374151', paddingHorizontal: 12, }, inputIcon: { fontSize: 16, marginRight: 8, }, input: { flex: 1, paddingVertical: 12, fontSize: 16, color: '#FFFFFF', }, eyeButton: { padding: 4, }, eyeIcon: { fontSize: 20, }, hintText: { fontSize: 12, color: '#6B7280', marginTop: 4, }, rowBetween: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16, }, checkboxContainer: { flexDirection: 'row', alignItems: 'center', }, checkbox: { width: 20, height: 20, borderRadius: 4, borderWidth: 2, borderColor: '#10B981', marginRight: 8, justifyContent: 'center', alignItems: 'center', }, checkboxChecked: { backgroundColor: '#10B981', }, checkmark: { color: '#FFFFFF', fontSize: 12, fontWeight: 'bold', }, checkboxLabel: { fontSize: 14, color: '#9CA3AF', }, linkText: { fontSize: 14, color: '#10B981', fontWeight: '500', }, errorContainer: { flexDirection: 'row', alignItems: 'center', backgroundColor: 'rgba(239, 68, 68, 0.1)', borderWidth: 1, borderColor: 'rgba(239, 68, 68, 0.3)', borderRadius: 8, padding: 12, marginBottom: 16, }, errorIcon: { fontSize: 16, marginRight: 8, }, errorText: { flex: 1, fontSize: 14, color: '#FCA5A5', }, primaryButton: { paddingVertical: 14, borderRadius: 8, alignItems: 'center', marginTop: 8, }, signInButton: { backgroundColor: '#059669', }, signUpButton: { backgroundColor: '#D97706', }, primaryButtonText: { fontSize: 16, fontWeight: 'bold', color: '#FFFFFF', }, buttonDisabled: { opacity: 0.5, }, footer: { marginTop: 24, alignItems: 'center', }, footerText: { fontSize: 12, color: '#6B7280', textAlign: 'center', }, footerLinks: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'center', marginTop: 4, }, footerLink: { fontSize: 12, color: '#10B981', }, }); export default AuthScreen;