import { useState } from 'react'; import { useNavigate, Link } from 'react-router-dom'; import { useAuth } from '../../lib/authContext'; 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 { BookOpen, Mail } from 'lucide-react'; import { useLanguage } from '../../lib/languageContext'; import { translations } from '../../lib/translations'; import { LanguageSwitcher } from '../LanguageSwitcher'; export function SignIn() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const { signIn } = useAuth(); const { language } = useLanguage(); const t = translations[language].auth; const navigate = useNavigate(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(null); try { const user = await signIn(email, password); const role = user?.role?.toLowerCase(); const approval = user?.sheikhApprovalStatus?.toLowerCase(); console.log(approval); if (role === 'student') { navigate('/student/dashboard'); } else if (role === 'admin') { navigate('/admin/dashboard'); } else if (role === 'sheikh') { if(approval ==='rejected'){ navigate('/sheikh/interview'); } else if (!user.profileCompleted) { navigate('/complete-profile/sheikh'); } else if (approval === 'approved') { navigate('/sheikh/dashboard'); } else { navigate('/sheikh/interview'); } } else { navigate('/'); } } catch (err) { console.error('Login error:', err); setError(err instanceof Error ? err.message : 'Login failed'); setLoading(false); } }; const handleGoogleSignIn = async () => { navigate('/auth/google'); }; const handleForgotPassword = () => { navigate('/forgot-password'); }; return (
{t.welcomeTitle} {t.welcomeDescription}
{/* Google Login */}
{t.orContinueWith}
{/* Email / Password */}
setEmail(e.target.value)} className="pl-10" required />
setPassword(e.target.value)} required />
{error && (

{error}

)}
{t.noAccount} {t.signUpLink}
); }