import { useState, type FormEvent } from 'react' import { useNavigate } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { useAuth } from '../../auth' type UnlockStep = 'idle' | 'authenticating' | 'downloadingKey' | 'decrypting' | 'startingServices' | 'ready' const STEP_KEYS: Record = { idle: '', authenticating: 'login.authenticating', downloadingKey: 'login.downloadingKey', decrypting: 'login.decrypting', startingServices: 'login.startingServices', ready: 'login.ready', } export default function LoginPage() { const { t } = useTranslation() const { login } = useAuth() const navigate = useNavigate() const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [step, setStep] = useState('idle') const runUnlockSequence = async () => { const steps: UnlockStep[] = ['downloadingKey', 'decrypting', 'startingServices', 'ready'] for (const s of steps) { setStep(s) await new Promise(r => setTimeout(r, 600)) } navigate('/flights') } const handleSubmit = async (e: FormEvent) => { e.preventDefault() setError('') setStep('authenticating') try { await login(email, password) await runUnlockSequence() } catch { setStep('idle') setError(t('login.error')) } } return (

{t('login.title')}

{step !== 'idle' && (
{t(STEP_KEYS[step])}
)} {step === 'idle' && ( <>
setEmail(e.target.value)} className="w-full bg-az-bg border border-az-border rounded px-3 py-2 text-az-text outline-none focus:border-az-orange" required autoFocus />
setPassword(e.target.value)} className="w-full bg-az-bg border border-az-border rounded px-3 py-2 text-az-text outline-none focus:border-az-orange" required />
{error &&
{error}
} )}
) }