'use client' import { useState } from 'react' import { useTranslations } from 'next-intl' import { useAuth } from './auth-provider' import { Box, TextField, Button, Alert, CircularProgress, InputAdornment, IconButton } from '@mui/material' import { Email, Lock, Visibility, VisibilityOff } from '@mui/icons-material' interface LoginFormProps { onSuccess?: () => void } export function LoginForm({ onSuccess }: LoginFormProps) { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [loading, setLoading] = useState(false) const [error, setError] = useState('') const [showPassword, setShowPassword] = useState(false) const { login } = useAuth() const t = useTranslations('auth') const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError('') try { const result = await login(email, password) if (result.success) { if (onSuccess) { onSuccess() } } else { setError(result.error || t('loginError')) } } catch (error) { setError(t('connectionError')) } finally { setLoading(false) } } const handleClickShowPassword = () => { setShowPassword(!showPassword) } return ( setEmail(e.target.value)} required margin="normal" variant="outlined" disabled={loading} InputProps={{ startAdornment: ( ), }} /> setPassword(e.target.value)} required margin="normal" variant="outlined" disabled={loading} InputProps={{ startAdornment: ( ), endAdornment: ( {showPassword ? : } ), }} /> {error && ( {error} )} ) }