'use client'; import { useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import toast, { Toaster } from 'react-hot-toast'; import { Mail, Key, Lock, CheckCircle, ArrowLeft, RefreshCw } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { requestForgetPasswordOtp, verifyForgetPasswordOtp } from '../utils/api'; export default function ForgotPasswordPage() { const router = useRouter(); const { t } = useTranslation(); const [step, setStep] = useState(1); const [email, setEmail] = useState(''); const [code, setCode] = useState(''); const [newPassword, setNewPassword] = useState(''); const [isLoading, setIsLoading] = useState(false); const handleRequestOtp = async (e) => { e.preventDefault(); if (!email.trim()) { toast.error(t('forgotPassword.emailRequired')); return; } setIsLoading(true); try { await requestForgetPasswordOtp(email); toast.success(t('forgotPassword.otpSent')); setStep(2); } catch (err) { toast.error(err?.message || t('forgotPassword.otpSendFailed')); } finally { setIsLoading(false); } }; const handleVerifyOtp = async (e) => { e.preventDefault(); if (!code.trim()) { toast.error(t('forgotPassword.otpRequired')); return; } if (newPassword.length < 6) { toast.error(t('validation.passwordMinLength')); return; } setIsLoading(true); try { await verifyForgetPasswordOtp(email, code, newPassword); toast.success(t('forgotPassword.resetSuccess')); setTimeout(() => router.push('/login'), 1200); } catch (err) { toast.error(err?.message || t('forgotPassword.otpVerifyFailed')); } finally { setIsLoading(false); } }; const inputClass = "w-full pr-12 pl-4 py-3 bg-white/10 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent text-gray-900 placeholder-gray-400 transition-all"; return (