import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Box, Button, Container, TextField, Typography, Paper, Alert, CircularProgress, Select, MenuItem, FormControl, } from '@mui/material'; import { useAuth } from '../contexts/AuthContext'; import { useI18n } from '../contexts/I18nContext'; import toast from 'react-hot-toast'; const LoginPage: React.FC = () => { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const navigate = useNavigate(); const { login } = useAuth(); const { t, language, changeLanguage } = useI18n(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); try { await login(username, password); toast.success(t('login.success')); navigate('/dashboard', { replace: true }); } catch (err: unknown) { const message = err instanceof Error ? err.message : t('login.failedHint'); setError(message); toast.error(t('login.failed')); } finally { setLoading(false); } }; return ( 🔄 {t('app.title')} {t('login.subtitle')} {error && ( {error} )} setUsername(e.target.value)} disabled={loading} sx={{ '& .MuiOutlinedInput-root': { borderRadius: 2, }, }} /> setPassword(e.target.value)} disabled={loading} sx={{ '& .MuiOutlinedInput-root': { borderRadius: 2, }, }} /> ); }; export default LoginPage;