constsubmit=async(e:React.FormEvent)=>{e.preventDefault();setError('');if(password!==confirm)returnsetError('Mật khẩu xác nhận không khớp.');setLoading(true);try{awaitapi.post('/auth/reset-password',{token,password});setSuccess(true);}catch(err:any){setError(err.response?.data?.message||'Liên kết không hợp lệ hoặc đã hết hạn.');}finally{setLoading(false);}};
const[confirm,setConfirm]=useState('');
return<AuthCardtitle="Đặt lại mật khẩu"subtitle="Tạo mật khẩu mới cho tài khoản của bạn.">{!token?<divclassName="rounded-lg bg-rose-50 p-4 text-sm text-rose-700">Thiếu mã đặt lại mật khẩu.</div>:success?<divclassName="space-y-4 text-center"><divclassName="rounded-lg bg-emerald-50 p-4 text-sm text-emerald-700">Đổi mật khẩu thành công.</div><Linkto="/login"className="font-semibold text-indigo-600">Đăng nhập ngay</Link></div>:<formonSubmit={submit}className="space-y-4">{error&&<divclassName="rounded-lg bg-rose-50 p-3 text-sm text-rose-700">{error}</div>}<inputtype="password"requiredminLength={8}value={password}onChange={e=>setPassword(e.target.value)}placeholder="Mật khẩu mới"className="w-full rounded-lg border border-slate-300 px-3 py-2.5"/><inputtype="password"requiredvalue={confirm}onChange={e=>setConfirm(e.target.value)}placeholder="Xác nhận mật khẩu"className="w-full rounded-lg border border-slate-300 px-3 py-2.5"/><pclassName="text-xs text-slate-500">Ít nhất 8 ký tự, gồm chữ hoa, chữ thường, số và ký tự đặc biệt.</p><buttondisabled={loading}className="flex w-full justify-center rounded-lg bg-indigo-600 py-3 font-semibold text-white">{loading?<Loader2className="h-5 w-5 animate-spin"/>:'Đặt lại mật khẩu'}</button></form>}</AuthCard>;