"use client"; import { useState } from "react"; import { motion } from "framer-motion"; import { useRouter } from "next/navigation"; import toast, { Toaster } from "react-hot-toast"; import { Lock, Eye, EyeOff, ArrowLeft, Shield } from "lucide-react"; import { useTranslation } from "react-i18next"; import { changePassword } from "../utils/api"; import AuthService from "../services/AuthService"; import InteractiveBackground from "../components/Animation/Background"; export default function ChangePasswordPage() { const router = useRouter(); const { t } = useTranslation(); const [form, setForm] = useState({ oldPassword: "", newPassword: "", confirmPassword: "" }); const [show, setShow] = useState({ old: false, new: false, confirm: false }); const [isLoading, setIsLoading] = useState(false); const handleChange = (field) => (e) => setForm({ ...form, [field]: e.target.value }); const toggleShow = (field) => setShow({ ...show, [field]: !show[field] }); const handleSubmit = async (e) => { e.preventDefault(); if (!AuthService.isAuthenticated()) { toast.error(t("changePassword.loginRequired")); router.push("/login"); return; } if (form.newPassword !== form.confirmPassword) { toast.error(t("changePassword.passwordsDoNotMatch")); return; } if (form.newPassword.length < 6) { toast.error(t("validation.passwordMinLength")); return; } setIsLoading(true); try { await changePassword(form.oldPassword, form.newPassword); toast.success(t("changePassword.changeSuccess")); setTimeout(() => router.push("/profile"), 1200); } catch (err) { toast.error(err?.message || t("changePassword.changeFailed")); } finally { setIsLoading(false); } }; const inputClass = "w-full pr-12 pl-4 py-3 bg-gray-50 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 (
{t("changePassword.title")} {t("changePassword.subtitle")}
{isLoading ? (
{t("changePassword.saving")}
) : ( t("changePassword.changePassword") )}
); }