import React, { useState } from 'react' import { useNavigate, Link } from 'react-router-dom' import { useAuth } from '@/context/AuthContext' import { useLang } from '@/context/LangContext' const GOLD = '#CD9E53' const NAVY = '#032340' export default function LoginPage() { const { lang } = useLang() const { login } = useAuth() const navigate = useNavigate() const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const T = { title: lang === 'fa' ? 'ورود به حساب' : 'Sign In', email: lang === 'fa' ? 'ایمیل' : 'Email', pass: lang === 'fa' ? 'رمز عبور' : 'Password', submit: lang === 'fa' ? 'ورود' : 'Login', noAcc: lang === 'fa' ? 'حساب ندارید؟' : "Don't have an account?", register: lang === 'fa' ? 'ثبت‌نام کنید' : 'Register', } async function handleSubmit(e: React.FormEvent) { e.preventDefault() setError('') setLoading(true) try { await login(email, password) navigate('/profile') } catch (err: unknown) { setError(err instanceof Error ? err.message : 'خطا در ورود') } finally { setLoading(false) } } return (

{T.title}

setEmail(e.target.value)} style={inputStyle} placeholder="example@email.com" dir="ltr" />
setPassword(e.target.value)} style={inputStyle} dir="ltr" />
{error && (

{error}

)}

{T.noAcc}{' '} {T.register}

) } const inputStyle: React.CSSProperties = { width: '100%', padding: '0.75rem 1rem', borderRadius: 8, border: '1px solid var(--rule-thin)', background: 'var(--paper)', color: 'var(--ink)', fontSize: '0.95rem', outline: 'none', boxSizing: 'border-box', } const btnStyle = (loading: boolean): React.CSSProperties => ({ width: '100%', padding: '0.85rem', borderRadius: 8, background: loading ? 'var(--ink-5)' : GOLD, color: NAVY, fontWeight: 700, fontSize: '1rem', border: 'none', cursor: loading ? 'not-allowed' : 'pointer', transition: 'opacity 0.2s', })