import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { useAuthStore } from '@/store/authStore' import { apiClientV2 } from '@/services/apiV2' import { Lock, User, LayoutDashboard, AlertCircle, Loader2 } from 'lucide-react' import LanguageSwitcher from '@/components/LanguageSwitcher' export default function LoginPage() { const { t } = useTranslation() const navigate = useNavigate() const setUser = useAuthStore((state) => state.setUser) const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') setLoading(true) try { const response = await apiClientV2.login({ username, password }) setUser({ id: response.user.id, username: response.user.email, email: response.user.email, displayName: response.user.display_name }) navigate('/upload') } catch (err: any) { const errorDetail = err.response?.data?.detail if (Array.isArray(errorDetail)) { setError(errorDetail.map((e: any) => e.msg || e.message || String(e)).join(', ')) } else if (typeof errorDetail === 'string') { setError(errorDetail) } else { setError(t('auth.loginError')) } } finally { setLoading(false) } } return (
{/* Top bar with language switcher */}
{/* Centered login form */}
{/* Logo and title */}

{t('app.title')}

{t('app.subtitle')}

{/* Login card */}

{t('auth.welcomeBack')}

{t('auth.loginPrompt')}

{/* Username */}
setUsername(e.target.value)} className="w-full pl-10 pr-4 py-2.5 bg-background border border-border rounded-lg text-foreground placeholder-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors" placeholder={t('auth.usernamePlaceholder')} required />
{/* Password */}
setPassword(e.target.value)} className="w-full pl-10 pr-4 py-2.5 bg-background border border-border rounded-lg text-foreground placeholder-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors" placeholder={t('auth.passwordPlaceholder')} required />
{/* Error message */} {error && (

{error}

)} {/* Submit button */}
{/* Supported formats info */}

{t('auth.supportedFormats')}

) }