import React, { useState } from 'react'; import { X, Loader2, GraduationCap, School, KeyRound, UserPlus } 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 [name, setName] = useState(''); const [role, setRole] = useState('student'); const [isRegistering, setIsRegistering] = useState(false); const [error, setError] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const { login, register, logout } = useAuth(); const navigate = useNavigate(); if (!isOpen) return null; const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); setError(''); setIsSubmitting(true); if (isRegistering && role === 'professor') { setIsSubmitting(false); setError('Contas de instrutor são liberadas pelo administrador da plataforma.'); return; } const signedInUser = isRegistering ? await register(name, email, password) : await login(email, password); setIsSubmitting(false); if (!signedInUser) { setError(isRegistering ? 'Não foi possível criar sua conta. Use um e-mail válido e uma senha com pelo menos 12 caracteres.' : 'Credenciais inválidas. Verifique seu e-mail e senha.'); return; } if (signedInUser.role !== role) { logout(); setError(role === 'professor' ? 'Esta conta não possui acesso de instrutor.' : 'Esta conta possui acesso de instrutor. Selecione a opção Instrutor.'); return; } onClose(); navigate(signedInUser.role === 'professor' ? '/gerenciar' : '/'); }; const handleDemoLogin = (roleType: UserRole) => { setRole(roleType); setIsRegistering(false); if (roleType === 'professor') { setEmail('admin@compor.local'); setPassword('ComporAdmin123!'); } else { setEmail('student@compor.local'); setPassword('ComporStudent123!'); } setError(''); }; return (

Compor HUB ID

Acesse seu espaço de aprendizado e materiais

{isRegistering && setName(event.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" required autoFocus />} setEmail(event.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" required autoFocus={!isRegistering} /> setPassword(event.target.value)} minLength={12} 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" required />
{!isRegistering && (
)} {error &&

{error}

}
); };