"use client"; import { useState, useEffect } from "react"; import { Eye, EyeOff, Lock, Fingerprint, ArrowLeft, ArrowRight, CheckCircle } from "lucide-react"; import { useLanguage } from "@/components/language-provider"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; export default function ResetPasswordPage() { const { lang, dir } = useLanguage(); const [mounted, setMounted] = useState(false); const [token, setToken] = useState(""); useEffect(() => { setMounted(true); const params = new URLSearchParams(window.location.search); setToken(params.get("token") || ""); }, []); const Arrow = lang === "fa" ? ArrowRight : ArrowLeft; const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [showPassword, setShowPassword] = useState(false); const [step, setStep] = useState<"set" | "success">("set"); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); if (password !== confirmPassword) { setError(lang === "fa" ? "رمزها مطابقت ندارند" : "Passwords do not match"); return; } if (password.length < 10) { setError(lang === "fa" ? "رمز باید حداقل ۱۰ کاراکتر باشد" : "Password must be at least 10 characters"); return; } if (!token) { setError(lang === "fa" ? "توکن نامعتبر است" : "Invalid token"); return; } setLoading(true); try { const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/auth/password/reset/confirm/`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token, new_password: password }), }); const data = await res.json(); if (!res.ok) { throw new Error(data.detail || data.error || "Reset failed"); } setStep("success"); } catch (err) { setError(err instanceof Error ? err.message : "Reset failed"); } finally { setLoading(false); } }; return (
{process.env.NEXT_PUBLIC_SITE_NAME || "MyAccount Hamsoo"} {step === "set" ? ( <>

{lang === "fa" ? "تنظیم رمز عبور جدید" : "Set New Password"}

{lang === "fa" ? "رمز عبور جدید خود را وارد کنید" : "Enter your new password"}

) : ( <>

{lang === "fa" ? "رمز با موفقیت تغییر کرد" : "Password Changed"}

{lang === "fa" ? "اکنون می‌توانید با رمز جدید وارد شوید" : "You can now sign in with your new password"}

)}
{error && (
{error}
)} {step === "set" && (
setPassword(e.target.value)} required minLength={10} className="w-full pl-10 pr-12 py-2.5 rounded-lg border border-white/10 bg-white/5 text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-brand-500/50 focus:border-transparent" placeholder={lang === "fa" ? "حداقل ۱۰ کاراکتر" : "At least 10 characters"} dir="ltr" />
setConfirmPassword(e.target.value)} required minLength={10} className="w-full pl-10 pr-4 py-2.5 rounded-lg border border-white/10 bg-white/5 text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-brand-500/50 focus:border-transparent" placeholder={lang === "fa" ? "رمز را مجدداً وارد کنید" : "Re-enter password"} dir="ltr" />
)} {step === "success" && (
)}
{lang === "fa" ? "مرکز حساب همسو" : "MyAccount Hamsoo"}
); }