'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { useAuthStore } from '@/lib/auth-store'; import { useTheme } from '@/lib/theme-store'; import { Eye, EyeOff, Sun, Moon, ArrowRight, ArrowLeft, Loader2, TicketCheck, Users, TrendingUp, ShieldCheck, MailCheck, } from 'lucide-react'; import { iamAuthApi } from '@/lib/api/auth'; const EDR_GREEN = 'rgb(20, 113, 76)'; const features = [ { icon: TicketCheck, label: 'Booking Management', desc: 'Full lifecycle booking operations' }, { icon: Users, label: 'Passenger Services', desc: 'Profiles, loyalty & wallet' }, { icon: TrendingUp, label: 'Revenue Analytics', desc: 'Real-time reports & insights' }, { icon: ShieldCheck, label: 'Fraud Detection', desc: 'Automated risk monitoring' }, ]; export default function LoginPage() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [showPassword, setShowPassword] = useState(false); const [isMounted, setIsMounted] = useState(false); const [emailFocused, setEmailFocused] = useState(false); const [passwordFocused, setPasswordFocused] = useState(false); const [view, setView] = useState<'login' | 'forgot'>('login'); const [forgotIdentifier, setForgotIdentifier] = useState(''); const [forgotLoading, setForgotLoading] = useState(false); const [forgotError, setForgotError] = useState(''); const [forgotSent, setForgotSent] = useState(false); const [forgotFocused, setForgotFocused] = useState(false); const router = useRouter(); const { login } = useAuthStore(); const { isDark, toggleTheme } = useTheme(); useEffect(() => { setIsMounted(true); }, []); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); try { await login(email, password); router.push('/dashboard'); } catch (err: any) { const msg = err.message || err.response?.data?.message || ''; if (msg === 'ACCESS_DENIED') { setError('This account does not have back-office access. Contact your administrator.'); } else { setError(err.response?.data?.message || msg || 'Invalid credentials. Please try again.'); } } finally { setLoading(false); } }; const handleForgotSubmit = async (e: React.FormEvent) => { e.preventDefault(); setForgotLoading(true); setForgotError(''); try { await iamAuthApi.forgotPassword(forgotIdentifier.trim()); setForgotSent(true); } catch (err: any) { const msg = err.response?.data?.message || err.message || ''; setForgotError( msg === 'user_not_found' ? 'No account found with that email or phone number.' : msg || 'Failed to send the reset link. Please try again.' ); } finally { setForgotLoading(false); } }; const backToLogin = () => { setView('login'); setForgotError(''); setForgotSent(false); }; if (!isMounted) return null; return (
{/* ── LEFT PANEL — form ── */}
{/* Top bar */}
{/* Logo — always visible on the form panel */}
ETHIO-DJIBOUTI
Railway
{/* Form area */}
{view === 'login' ? ( <> {/* Heading */}

Sign in to continue

Enter your credentials to access the back-office.

{/* Error */} {error && (
!

{error}

)}
{/* Email field */}
{ setEmail(e.target.value); setError(''); }} onFocus={() => setEmailFocused(true)} onBlur={() => setEmailFocused(false)} className="w-full px-4 py-3 rounded-xl bg-white dark:bg-gray-900 text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-gray-600 text-sm focus:outline-none" placeholder="name@edr.com" required autoComplete="email" />
{/* Password field */}
{ setPassword(e.target.value); setError(''); }} onFocus={() => setPasswordFocused(true)} onBlur={() => setPasswordFocused(false)} className="w-full px-4 py-3 pr-11 rounded-xl bg-white dark:bg-gray-900 text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-gray-600 text-sm focus:outline-none" placeholder="••••••••••" required autoComplete="current-password" />
{/* Submit */}
{/* Divider */}

Access is restricted to authorised EDR staff only. All sessions are logged and audited.

) : ( <> {/* Heading */}

Reset your password

Enter your email or phone number and we'll send a reset link to the phone number on your account.

{forgotSent ? (

A password reset link has been sent via SMS. Open it to set a new password — the link expires in 30 minutes.

) : ( <> {/* Error */} {forgotError && (
!

{forgotError}

)}
{/* Email or phone field */}
{ setForgotIdentifier(e.target.value); setForgotError(''); }} onFocus={() => setForgotFocused(true)} onBlur={() => setForgotFocused(false)} className="w-full px-4 py-3 rounded-xl bg-white dark:bg-gray-900 text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-gray-600 text-sm focus:outline-none" placeholder="name@edr.com or +251..." required autoComplete="username" />
{/* Submit */}
)} )}
{/* Bottom bar */}
Back-office · v1.0 Need help? edr_@edrsc.com
{/* ── RIGHT PANEL — photo ── */}
{/* Layer 1 — base photo, desaturated */}
{/* Layer 2 — brand green color wash */}
{/* Content */}
{/* Badge */}
Back-office Portal v1.0
{/* Hero text */}

Passenger
Management
System

Unified platform for booking operations, passenger services, revenue analytics, and real-time train management.

{/* Feature grid */}
{features.map(({ icon: Icon, label, desc }) => (
{label}
{desc}
))}
{/* Bottom rule */}
© 2026 Ethio-Djibouti Railway S.C. — Secure · Encrypted · Monitored
); }