'use client'; import React, { useState } from 'react'; import Link from 'next/link'; import { motion } from 'framer-motion'; import { User, Shield, ArrowRight, Activity } from 'lucide-react'; import { useRouter } from 'next/navigation'; import { AuthProvider, useAuth } from '@/lib/auth'; export default function LandingPageWrap() { return ( ); } function LandingPage() { const router = useRouter(); const { login } = useAuth(); const [role, setRole] = useState<'coach' | 'client' | null>(null); const [userId, setUserId] = useState(''); const [status, setStatus] = useState(''); const [isLoading, setIsLoading] = useState(false); // Registration State const [isRegistering, setIsRegistering] = useState(false); const [regName, setRegName] = useState(''); const [regRole, setRegRole] = useState<'COACH' | 'CLIENT' | null>(null); const [generatedUser, setGeneratedUser] = useState(null); const handleRegister = async (e: React.FormEvent) => { e.preventDefault(); if (!regName || !regRole) return; setIsLoading(true); setStatus('Creating Account...'); try { const res = await fetch('/api/register', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: regName, role: regRole }) }); if (res.ok) { const newUser = await res.json(); setGeneratedUser(newUser); setStatus('Account Created!'); } else { setStatus('Registration Failed'); } } catch (err) { setStatus('Error connecting to server'); } finally { setIsLoading(false); } }; const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); if (!role || !userId) return; setIsLoading(true); setStatus('Validating credentials...'); try { const user = await login(userId); if (user) { // Role Validation if (role === 'coach') { if (user.role !== 'COACH') { setStatus('Access Denied: You are not a Coach'); setIsLoading(false); return; } setStatus('Authenticated. Redirecting...'); router.push('/coach/dashboard'); } else { if (user.role !== 'CLIENT') { setStatus('Access Denied: You are not a Client'); setIsLoading(false); return; } setStatus('Authenticated. Redirecting...'); router.push('/client'); } } else { setStatus('Invalid User ID'); setIsLoading(false); } } catch (err) { setStatus('Connection Error'); setIsLoading(false); } }; return (
{/* Decorative Background Elements */}
{/* Logo / Header */}

STRAPS-R

Strength Training Pose Recognition and Patient Rehabilitation

{/* Login / Register Card */}
{/* Mode Toggle */}
{isRegistering ? ( generatedUser ? (

Welcome, {generatedUser.name}!

Your account has been created.

Your Unique User ID

{generatedUser.id}

Please save this ID. You will need it to login.

) : (
setRegName(e.target.value)} className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-4 py-3 text-lg focus:outline-none focus:border-zinc-400 transition-colors text-zinc-900" />
) ) : ( <> {/* Role Selection */}
{/* Login Form */}
setUserId(e.target.value)} className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-4 py-4 text-lg text-center tracking-widest focus:outline-none focus:border-zinc-400 transition-colors disabled:opacity-50 disabled:cursor-not-allowed text-zinc-900 placeholder:text-zinc-300 font-mono" /> {status &&

{status}

}
)} {/* Active Status Indicator */}

SECURE ACCESS • v2.0.4

); }