'use client' import { useState, useEffect, Suspense } from 'react' import { useSearchParams, useRouter } from 'next/navigation' import { Header } from '@/components/Header' import { Footer } from '@/components/Footer' import { api } from '@/lib/api' import { Lock, Eye, EyeOff, CheckCircle, AlertCircle, ArrowLeft } from 'lucide-react' import Link from 'next/link' import clsx from 'clsx' function ResetPasswordContent() { const searchParams = useSearchParams() const router = useRouter() const token = searchParams.get('token') const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [showPassword, setShowPassword] = useState(false) const [loading, setLoading] = useState(false) const [success, setSuccess] = useState(false) const [error, setError] = useState(null) useEffect(() => { if (!token) { setError('Invalid or missing reset token. Please request a new password reset link.') } }, [token]) const validatePassword = (pwd: string): string | null => { if (pwd.length < 8) { return 'Password must be at least 8 characters' } return null } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() const passwordError = validatePassword(password) if (passwordError) { setError(passwordError) return } if (password !== confirmPassword) { setError('Passwords do not match') return } if (!token) { setError('Invalid reset token') return } setLoading(true) setError(null) try { await api.resetPassword(token, password) setSuccess(true) // Redirect to login after 3 seconds setTimeout(() => { router.push('/login?reset=success') }, 3000) } catch (err: any) { setError(err.message || 'Failed to reset password. The link may have expired.') } finally { setLoading(false) } } const passwordStrength = (pwd: string): { label: string; color: string; width: string } => { if (pwd.length === 0) return { label: '', color: 'bg-transparent', width: 'w-0' } if (pwd.length < 6) return { label: 'Weak', color: 'bg-danger', width: 'w-1/4' } if (pwd.length < 8) return { label: 'Fair', color: 'bg-warning', width: 'w-2/4' } if (pwd.length < 12) return { label: 'Good', color: 'bg-accent', width: 'w-3/4' } return { label: 'Strong', color: 'bg-accent', width: 'w-full' } } const strength = passwordStrength(password) return ( <>
Back to login {success ? (

Password reset successful

Your password has been reset. Redirecting you to login...

Go to login
) : (

Reset your password

Enter your new password below.

{error && (

{error}

)}
setPassword(e.target.value)} required minLength={8} placeholder="At least 8 characters" className="w-full pl-12 pr-12 py-3 bg-background-tertiary border border-border rounded-xl text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-accent/30 focus:border-accent transition-all" />
{/* Password strength indicator */} {password && (

{strength.label}

)}
setConfirmPassword(e.target.value)} required minLength={8} placeholder="Confirm your password" className="w-full pl-12 pr-4 py-3 bg-background-tertiary border border-border rounded-xl text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-accent/30 focus:border-accent transition-all" />
{confirmPassword && password !== confirmPassword && (

Passwords do not match

)}
)}