import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Button } from '../ui/button'; import { Input } from '../ui/input'; import { Label } from '../ui/label'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '../ui/card'; import { RadioGroup, RadioGroupItem } from '../ui/radio-group'; import { BookOpen, Mail, User, Phone } from 'lucide-react'; import { useAuth } from '../../lib/authContext'; import { useLanguage } from '../../lib/languageContext'; import { translations } from '../../lib/translations'; import { LanguageSwitcher } from '../LanguageSwitcher'; export function Register() { const [fullName, setFullName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [phone, setPhone] = useState(''); const [gender, setGender] = useState('Male'); const [country, setCountry] = useState(''); const [birthDate, setBirthDate] = useState(''); const [role, setRole] = useState<'student' | 'sheikh'>('student'); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const { signUp } = useAuth(); const { language } = useLanguage(); const navigate = useNavigate(); const isRTL = language === 'ar'; const t = translations[language].auth; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); setLoading(true); try { if (!birthDate) throw new Error(t.error?.birthDateRequired || 'تاريخ الميلاد مطلوب'); if (!country) throw new Error(t.error?.countryRequired || 'الدولة مطلوبة'); await signUp(email, password, fullName, role, phone, gender, country, birthDate); // التنقل لصفحة إكمال الملف الشخصي أو الصفحة الرئيسية حسب منطق التطبيق navigate('/complete-profile'); } catch (err: any) { console.error('Registration error:', err); setError(err.message || t.error?.general || 'فشل التسجيل، حاول مرة أخرى'); } finally { setLoading(false); } }; return (
{t.createAccount} {t.createAccountDescription}
{/* الاسم الكامل */}
setFullName(e.target.value)} className="pl-10" required />
setFullName(e.target.value)} className="pl-10" required />
{/* البريد الإلكتروني */}
setEmail(e.target.value)} className="pl-10" required />
{/* كلمة المرور */}
setPassword(e.target.value)} required />
{/* رقم الهاتف */}
setPhone(e.target.value)} className={isRTL ? 'pr-10 text-right' : 'pl-10'} dir={isRTL ? 'rtl' : 'ltr'} required />
{/* الجنس */}
{/* الدولة */}
{/* تاريخ الميلاد */}
setBirthDate(e.target.value)} className={isRTL ? 'text-right' : 'pl-10'} dir={isRTL ? 'rtl' : 'ltr'} required />
{/* الدور (طالب / شيخ) */}
setRole(value as 'student' | 'sheikh')} >
{error && (

{error}

)}
); }