import React, { useState, useEffect, useRef } from 'react'; import { useAuth } from '../store/AuthContext'; import { useNavigate } from 'react-router-dom'; import { ShieldCheck, Mail, Lock, Sparkles, ArrowRight, Eye, EyeOff, RefreshCw } from 'lucide-react'; /* ── Floating Particle ─────────────────────────────────────── */ interface Particle { id: number; x: number; y: number; size: number; opacity: number; delay: number; duration: number; } const generateParticles = (count: number): Particle[] => Array.from({ length: count }, (_, i) => ({ id: i, x: Math.random() * 100, y: Math.random() * 100, size: Math.random() * 4 + 2, opacity: Math.random() * 0.4 + 0.1, delay: Math.random() * 6, duration: Math.random() * 4 + 5, })); /* ── Animated Background ───────────────────────────────────── */ const AnimatedBackground: React.FC = () => { const [particles] = useState(() => generateParticles(25)); return (
{/* Mesh gradient base */}
{/* Large glowing orbs */}
{/* Morphing blob */}
{/* Grid overlay */}
{/* Floating particles */} {particles.map(p => (
))}
); }; /* ── 3D Orbiting Ring ──────────────────────────────────────── */ const OrbitingRing: React.FC = () => (
{/* Center icon */}
{/* Orbiting ring 1 */}
{/* Orbiting ring 2 */}
); /* ── Main LoginForm ────────────────────────────────────────── */ export const LoginForm: React.FC = () => { const { login, register, verifyMfa, mfaPendingEmail } = useAuth(); const navigate = useNavigate(); const [isRegister, setIsRegister] = useState(false); const [email, setEmail] = useState(''); const [showPass, setShowPass] = useState(false); const [otp, setOtp] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const [mousePos, setMousePos] = useState({ x: 0, y: 0 }); const cardRef = useRef(null); // Client Profile Registration States const [companyName, setCompanyName] = useState(''); const [website, setWebsite] = useState(''); const [sector, setSector] = useState('Technology'); const [companySize, setCompanySize] = useState('1-10'); /* 3D tilt effect on card */ const handleMouseMove = (e: React.MouseEvent) => { if (!cardRef.current) return; const rect = cardRef.current.getBoundingClientRect(); const x = (e.clientX - rect.left) / rect.width - 0.5; const y = (e.clientY - rect.top) / rect.height - 0.5; setMousePos({ x, y }); }; const handleMouseLeave = () => setMousePos({ x: 0, y: 0 }); const cardTransform = `perspective(1200px) rotateY(${mousePos.x * 8}deg) rotateX(${-mousePos.y * 6}deg) translateZ(0)`; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); if (!email) { setError('Email address is required.'); setLoading(false); return; } try { if (isRegister) { if (!companyName.trim() || !website.trim()) { setError('Please fill in all company information.'); setLoading(false); return; } await register(email, { companyName, website, sector, companySize }); } else { await login(email); } } catch (err: unknown) { setError(err instanceof Error ? err.message : 'Authentication failed.'); } finally { setLoading(false); } }; const handleMfaSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); if (otp.length !== 6) { setError('Enter the 6-digit verification code.'); setLoading(false); return; } try { const loggedUser = await verifyMfa(otp); navigate(loggedUser.role === 'ADMIN' ? '/admin' : '/client'); } catch (err: unknown) { setError(err instanceof Error ? err.message : 'MFA validation failed.'); } finally { setLoading(false); } }; const [mounted, setMounted] = useState(false); useEffect(() => { setTimeout(() => setMounted(true), 50); }, []); return (
{/* Card wrapper with 3D tilt */}
{/* Glow behind card */}
{/* Main glass card */}
{/* Top accent bar */}
{/* Brand Header */}

{mfaPendingEmail ? 'Verify Identity' : 'Tech4Biz Portal'}

{mfaPendingEmail ? `Code sent to ${mfaPendingEmail}` : 'Enterprise hardware & software asset distribution'}

{/* Mode toggle */} {!mfaPendingEmail && (
{(['Login', 'Sign Up'] as const).map(label => { const active = label === 'Login' ? !isRegister : isRegister; return ( ); })}
)}
{/* Error message */} {error && (
{error}
)} {/* ── Credentials Form ── */} {!mfaPendingEmail ? (
{/* Email field */}
setEmail(e.target.value)} placeholder="client@tech4biz.com" className="input-field has-left-icon" required />
{/* Password field (mock) */}

Mock password preset:{' '} password

{/* Register Profile Fields */} {isRegister && ( <>
setCompanyName(e.target.value)} placeholder="e.g. Acme Corporation" className="input-field" required />
setWebsite(e.target.value)} placeholder="https://example.com" className="input-field" required />
)} {/* Quick fill hints */} {!isRegister && (

Quick Access Accounts

{[ { label: 'Admin', email: 'admin@tech4biz.com' }, { label: 'Client', email: 'client@tech4biz.com' }, ].map(acc => ( ))}
)} {/* Submit */}
) : ( /* ── MFA Form ── */

Development Mode

Use code{' '} 123456

{/* OTP input */}
setOtp(e.target.value.replace(/\D/g, ''))} placeholder="000000" className="input-field text-center font-mono text-2xl tracking-[0.5em] py-4" required autoFocus />
)}
{/* Bottom accent */}

© 2026 Tech4Biz Solutions Inc. · Enterprise Security Portal

); };