"use client"; import React, { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; const RecPasswordCodePage = () => { const router = useRouter(); const [code, setCode] = useState(""); const [error, setError] = useState(""); const [secondsLeft, setSecondsLeft] = useState(60); const [isResending, setIsResending] = useState(false); const isCodeValid = code.length === 6; const canResend = secondsLeft === 0 && !isResending; // таймер на минуту useEffect(() => { if (secondsLeft <= 0) return; const timer = setInterval(() => { setSecondsLeft((prev) => prev - 1); }, 1000); return () => clearInterval(timer); }, [secondsLeft]); const handleSubmit = (e) => { e.preventDefault(); if (!isCodeValid) { setError("Код должен содержать 6 символов"); return; } setError(""); console.log("Подтверждение кода:", code); router.push("/home"); // TODO: запрос на бэк и переход на страницу смены пароля }; const handleChange = (e) => { const value = e.target.value.replace(/\D/g, "").slice(0, 6); setCode(value); if (error && value.length === 6) setError(""); }; const handleResend = async () => { if (!canResend) return; try { setIsResending(true); // фейковый запрос на повторную отправку кода await new Promise((resolve) => setTimeout(resolve, 1000)); console.log("Повторная отправка кода на почту"); setSecondsLeft(60); } finally { setIsResending(false); } }; const formatTime = (sec) => { const m = Math.floor(sec / 60) .toString() .padStart(2, "0"); const s = (sec % 60).toString().padStart(2, "0"); return `${m}:${s}`; }; return (