import { supabase } from '../supabaseClient'; import React, { useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; // --- SVG Icon Components --- const EyeIcon = () => (); const EyeOffIcon = () => (); export default function AppliLogin({ onNavigate }) { const [mode, setMode] = useState('login'); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [isPasswordVisible, setIsPasswordVisible] = useState(false); const [errors, setErrors] = useState({}); const [loading, setLoading] = useState(false); // Notification State const [notification, setNotification] = useState(null); const validate = () => { const newErrors = {}; if (!email.trim()) newErrors.email = 'Email is required.'; else if (!/\S+@\S+\.\S+/.test(email)) newErrors.email = 'Email is invalid.'; if (mode !== 'forgot') { if (!password) newErrors.password = 'Password is required.'; } if (mode === 'register') { if (password !== confirmPassword) newErrors.confirmPassword = 'Passwords do not match.'; } return newErrors; }; const handleSubmit = async (e) => { e.preventDefault(); const formErrors = validate(); if (Object.keys(formErrors).length > 0) { setErrors(formErrors); return; } setErrors({}); setLoading(true); setNotification(null); try { if (mode === 'login') { const { data, error } = await supabase.auth.signInWithPassword({ email, password, }); if (error) throw error; // Check role const role = data.user?.user_metadata?.role; if (role === 'applicant') { onNavigate('dashboard'); } else { setNotification({ type: 'error', message: 'Unauthorized role detected.' }); await supabase.auth.signOut(); } } else if (mode === 'register') { const { error } = await supabase.auth.signUp({ email, password, options: { data: { role: 'applicant' } } }); if (error) throw error; setNotification({ type: 'success', message: 'Registration successful! Please confirm your Email and login.' }); setMode('login'); } else if (mode === 'forgot') { const { error } = await supabase.auth.resetPasswordForEmail(email, { redirectTo: `${window.location.origin}/reset-password`, }); if (error) throw error; setNotification({ type: 'success', message: 'Password reset link sent! Check your email.' }); setMode('login'); } } catch (error) { setNotification({ type: 'error', message: error.message }); } finally { setLoading(false); } }; const formVariants = { hidden: { opacity: 0, y: 20 }, visible: { opacity: 1, y: 0 }, exit: { opacity: 0, y: -20 } }; const notificationStyles = { padding: '0.75rem 1rem', marginBottom: '1rem', borderRadius: '0.5rem', fontSize: '0.875rem', textAlign: 'center', border: '1px solid', }; return (
{/* --- 🔴 FIXED BACK BUTTON (Z-INDEX 999) --- */} {/* Background Orbs */} <>
{/* Notification */} {notification && ( {notification.message} )} {/* --- Login Form --- */} {mode === 'login' && (

IRIS

Applicant Portal

setEmail(e.target.value)} placeholder="lead@example.com" disabled={loading} style={{ width: '100%', padding: '0.75rem 1rem', backgroundColor: 'rgba(255, 255, 255, 0.1)', border: `1px solid ${errors.email ? '#EF4444' : 'rgba(251, 191, 36, 0.3)'}`, borderRadius: '0.5rem', color: 'white' }} /> {errors.email &&

{errors.email}

}
setPassword(e.target.value)} placeholder="••••••••" disabled={loading} style={{ width: '100%', padding: '0.75rem 3rem 0.75rem 1rem', backgroundColor: 'rgba(255, 255, 255, 0.1)', border: `1px solid ${errors.password ? '#EF4444' : 'rgba(251, 191, 36, 0.3)'}`, borderRadius: '0.5rem', color: 'white' }} />
{errors.password ?

{errors.password}

: }
{loading ? 'Signing In...' : 'Sign In'}

Don't have an account?

)} {/* --- Register Form --- */} {mode === 'register' && (

Create Account

setEmail(e.target.value)} disabled={loading} style={{ width: '100%', padding: '0.75rem 1rem', backgroundColor: 'rgba(255, 255, 255, 0.1)', border: `1px solid ${errors.email ? '#EF4444' : 'rgba(251, 191, 36, 0.3)'}`, borderRadius: '0.5rem', color: 'white' }} />
setPassword(e.target.value)} disabled={loading} style={{ width: '100%', padding: '0.75rem 1rem', backgroundColor: 'rgba(255, 255, 255, 0.1)', border: `1px solid ${errors.password ? '#EF4444' : 'rgba(251, 191, 36, 0.3)'}`, borderRadius: '0.5rem', color: 'white' }} />
setConfirmPassword(e.target.value)} disabled={loading} style={{ width: '100%', padding: '0.75rem 1rem', backgroundColor: 'rgba(255, 255, 255, 0.1)', border: `1px solid ${errors.confirmPassword ? '#EF4444' : 'rgba(251, 191, 36, 0.3)'}`, borderRadius: '0.5rem', color: 'white' }} />
{loading ? 'Registering...' : 'Register'}

Already have an account?

)} {/* --- Forgot Password --- */} {mode === 'forgot' && (

Forgot Password

setEmail(e.target.value)} disabled={loading} style={{ width: '100%', padding: '0.75rem 1rem', backgroundColor: 'rgba(255, 255, 255, 0.1)', border: `1px solid ${errors.email ? '#EF4444' : 'rgba(251, 191, 36, 0.3)'}`, borderRadius: '0.5rem', color: 'white' }} />
{loading ? 'Sending...' : 'Send Reset Link'}

)}
); }