import React, { useState, useEffect } from 'react'; import { useAuth } from '../contexts/AuthContext'; import { Users, Lock, Eye, EyeOff, XCircle, Mail, ArrowRight, CheckCircle, X, Sparkles, Shield, KeyRound } from 'lucide-react'; export const LoginPage: React.FC = () => { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [rememberMe, setRememberMe] = useState(false); const [error, setError] = useState(''); const [showError, setShowError] = useState(false); const [loading, setLoading] = useState(false); const { login } = useAuth(); // Forgot password modal state const [showForgotModal, setShowForgotModal] = useState(false); const [forgotEmail, setForgotEmail] = useState(''); const [forgotLoading, setForgotLoading] = useState(false); const [forgotSuccess, setForgotSuccess] = useState(false); const [forgotError, setForgotError] = useState(''); // Auto-hide error after 5 seconds useEffect(() => { if (error) { setShowError(true); const timer = setTimeout(() => { setShowError(false); setTimeout(() => setError(''), 300); }, 5000); return () => clearTimeout(timer); } }, [error]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); try { await login(username, password); } catch (err: unknown) { const error = err as Error; const errorMessage = error.message?.includes('401') || error.message?.includes('Unauthorized') || error.message?.includes('Invalid') ? 'Invalid username or password' : error.message || 'Login failed. Please check your credentials.'; setError(errorMessage); console.error('Login error:', err); } finally { setLoading(false); } }; const handleForgotPassword = async (e: React.FormEvent) => { e.preventDefault(); setForgotLoading(true); setForgotError(''); // Simulate API call (replace with actual API call) try { await new Promise(resolve => setTimeout(resolve, 1500)); // In a real app, you'd call: await api.requestPasswordReset(forgotEmail); setForgotSuccess(true); } catch { setForgotError('Failed to send reset email. Please try again.'); } finally { setForgotLoading(false); } }; const closeForgotModal = () => { setShowForgotModal(false); setForgotEmail(''); setForgotSuccess(false); setForgotError(''); }; return (
{/* Animated background elements */}
{/* Floating particles */}
{[...Array(20)].map((_, i) => (
))}
{/* Login Card */}
{/* Logo & Title */}

Welcome Back

Sign in to your account to continue

{/* Login Form */}
{/* Username Input */}
setUsername(e.target.value)} placeholder="Username" required autoComplete="username" className="w-full pl-12 pr-4 py-4 bg-white/10 border border-white/20 rounded-xl text-white placeholder-blue-200/50 focus:outline-none focus:ring-2 focus:ring-blue-400/50 focus:border-blue-400/50 focus:bg-white/15 transition-all" />
{/* Password Input */}
setPassword(e.target.value)} placeholder="Password" required autoComplete="current-password" className="w-full pl-12 pr-12 py-4 bg-white/10 border border-white/20 rounded-xl text-white placeholder-blue-200/50 focus:outline-none focus:ring-2 focus:ring-blue-400/50 focus:border-blue-400/50 focus:bg-white/15 transition-all" />
{/* Remember Me & Forgot Password */}
{/* Login Button */}
{/* Divider */}
{/* Footer Info */}
{/* Version badge */}
v2.0.0
{/* Error Toast */} {error && (

Login Failed

{error}

)} {/* Forgot Password Modal */} {showForgotModal && (
{/* Backdrop */}
{/* Modal */}
{/* Close button */} {!forgotSuccess ? ( <> {/* Header */}

Forgot Password?

Enter your email address and we'll send you instructions to reset your password.

{/* Form */}
setForgotEmail(e.target.value)} placeholder="Enter your email" required className="w-full pl-12 pr-4 py-4 bg-white/10 border border-white/20 rounded-xl text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-amber-400/50 focus:border-amber-400/50 transition-all" />
{forgotError && (

{forgotError}

)}
{/* Back to login */} ) : ( /* Success State */

Check Your Email

We've sent password reset instructions to
{forgotEmail}

)}
)} {/* CSS for floating animation */}
); };