import React, { useState } from 'react'; import { X, Loader2, GraduationCap, School, KeyRound } from 'lucide-react'; import { useAuth } from '../context/AuthContext'; import { useNavigate } from 'react-router-dom'; import { UserRole } from '../types'; interface LoginModalProps { isOpen: boolean; onClose: () => void; } export const LoginModal: React.FC = ({ isOpen, onClose }) => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [role, setRole] = useState('student'); // Default role const [error, setError] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const { login } = useAuth(); const navigate = useNavigate(); if (!isOpen) return null; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setIsSubmitting(true); // Simulate network delay for "premium" feel setTimeout(() => { // In a real app, the backend verifies credentials AND role matches. // Here we simulate checking if the user exists for that specific context. const success = login(email); setIsSubmitting(false); if (success) { onClose(); if (email === 'admin@prof.com') { // Force check: if they selected student but logged in as admin credentials, redirect correctly or warn. // For UX simplicity here, we trust the credential mapping in AuthContext navigate('/gerenciar'); } else { navigate('/'); } } else { setError('Credenciais inválidas. Verifique o email ou a função selecionada.'); } }, 800); }; const handleDemoLogin = (roleType: UserRole) => { const demoEmail = roleType === 'professor' ? 'admin@prof.com' : 'aluno@test.com'; setEmail(demoEmail); setPassword('demo123'); setRole(roleType); }; return (
{/* Backdrop */}
{/* Modal Content */}

Compor HUB ID

Acesse seu espaço de aprendizado e materiais

{/* Role Toggle */}
{/* Sliding Background */}
setEmail(e.target.value)} className="w-full bg-white/10 text-white placeholder:text-white/30 px-4 py-3 rounded-[8px] focus:outline-none focus:ring-2 focus:ring-orange-500/50 focus:bg-white/15 transition-all text-body tracking-body" autoFocus />
setPassword(e.target.value)} className="w-full bg-white/10 text-white placeholder:text-white/30 px-4 py-3 rounded-[8px] focus:outline-none focus:ring-2 focus:ring-orange-500/50 focus:bg-white/15 transition-all text-body tracking-body" />
{/* Quick Demo Buttons */}
{error && (

{error}

)}
); };