"use client"; import { useState, useRef } from "react"; import Image from "next/image"; import localFont from "next/font/local"; import { useGSAP } from "@gsap/react"; import gsap from "gsap"; import { Envelope, Lock, ShieldCheck, ArrowRight, CircleNotch, Eye, EyeSlash } from "@phosphor-icons/react"; import logo from '../../../public/logo.png'; const figtree = localFont({ src: [ { path: '../../../public/Fonts/figtree/figtree.ttf', }, ], }); // Reusing styles for consistency const inputStyle = `${figtree.className} w-full p-4 border-2 border-black text-lg outline-none focus:bg-[#F7F7F7] transition-colors placeholder:text-gray-400 bg-white`; const buttonStyle = `${figtree.className} w-full flex items-center justify-center gap-2 px-8 py-4 border-2 border-black bg-[#E7FE78] text-lg font-bold hover:bg-[#dcfc4e] transition-colors disabled:opacity-50 disabled:cursor-not-allowed shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] hover:translate-y-[2px] hover:shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] active:translate-y-[4px] active:shadow-none transition-all`; const labelStyle = `${figtree.className} text-sm font-bold uppercase tracking-wider mb-2 block`; function Login() { const [step, setStep] = useState<'credentials' | '2fa' | 'forgot-password' | 'recovery-sent'>('credentials'); const [isLoading, setIsLoading] = useState(false); const [formData, setFormData] = useState({ email: '', password: '', otp: '' }); const [error, setError] = useState(''); const [showPassword, setShowPassword] = useState(false); const formRef = useRef(null); const imageRef = useRef(null); useGSAP(() => { // Animate image side gsap.fromTo(imageRef.current, { x: -50, opacity: 0 }, { x: 0, opacity: 1, duration: 1, ease: "power3.out" } ); // Animate form side gsap.fromTo(formRef.current, { x: 50, opacity: 0 }, { x: 0, opacity: 1, duration: 1, delay: 0.2, ease: "power3.out" } ); }, []); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setIsLoading(true); // Simulate API call setTimeout(() => { setIsLoading(false); if (formData.email === 'asabizanjo@gmail.com' && formData.password === 'Balouch@12') { // Transition to 2FA gsap.to(formRef.current, { x: -20, opacity: 0, duration: 0.3, onComplete: () => { setStep('2fa'); gsap.fromTo(formRef.current, { x: 20, opacity: 0 }, { x: 0, opacity: 1, duration: 0.3 } ); } }); } else { setError('Invalid email or password'); } }, 1000); }; const handleVerify = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setIsLoading(true); // Simulate API call setTimeout(() => { setIsLoading(false); if (formData.otp === '0000') { alert('Login Successful! (JWT would be stored here)'); // Here you would store the JWT } else { setError('Invalid OTP. Please try again (Hint: 0000)'); } }, 1000); }; const handleForgotPasswordSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setIsLoading(true); // Simulate API call setTimeout(() => { setIsLoading(false); if (formData.email) { gsap.to(formRef.current, { x: -20, opacity: 0, duration: 0.3, onComplete: () => { setStep('recovery-sent'); gsap.fromTo(formRef.current, { x: 20, opacity: 0 }, { x: 0, opacity: 1, duration: 0.3 } ); } }); } else { setError('Please enter your email address'); } }, 1000); }; return (
{/* Left Side - Visual/Logo */}
Logo

Welcome Back

Your Home Away From Home

{/* Right Side - Form */}
{step === 'credentials' && ( <>

Sign In

Enter your details to access your account

setFormData({ ...formData, email: e.target.value })} />
setFormData({ ...formData, password: e.target.value })} />
{error && (
{error}
)}

Don't have an account?{' '} Sign Up

)} {step === '2fa' && ( <>

Two-Factor Auth

Enter the code sent to your device

setFormData({ ...formData, otp: e.target.value })} />

Use '0000' for testing

{error && (
{error}
)}
)} {step === 'forgot-password' && ( <>

Reset Password

Enter your email to receive a recovery link

setFormData({ ...formData, email: e.target.value })} />
{error && (
{error}
)}
)} {step === 'recovery-sent' && (

Check Your Email

We've sent a password recovery link to
{formData.email}

)}
); } export default Login;