import { useState, useEffect, useRef } from "react" import { BrandLogo } from "../../components/brand/BrandLogo" import { Button } from "../../components/ui/button" import { Input } from "../../components/ui/input" export function VerificationPage() { const [codes, setCodes] = useState(["", "", "", "", ""]) const [activeIndex, setActiveIndex] = useState(0) const [timeLeft, setTimeLeft] = useState(30) const inputRefs = useRef<(HTMLInputElement | null)[]>([]) useEffect(() => { if (timeLeft > 0) { const timer = setTimeout(() => setTimeLeft(timeLeft - 1), 1000) return () => clearTimeout(timer) } }, [timeLeft]) const handleCodeChange = (index: number, value: string) => { if (value.length > 1) { // Handle paste const pastedCodes = value.slice(0, 5).split("") const newCodes = [...codes] pastedCodes.forEach((code, i) => { if (index + i < 5) { newCodes[index + i] = code } }) setCodes(newCodes) const nextIndex = Math.min(index + pastedCodes.length, 4) setActiveIndex(nextIndex) inputRefs.current[nextIndex]?.focus() return } if (!/^\d*$/.test(value)) return // Only allow digits const newCodes = [...codes] newCodes[index] = value setCodes(newCodes) if (value && index < 4) { setActiveIndex(index + 1) inputRefs.current[index + 1]?.focus() } else if (!value && index > 0) { setActiveIndex(index - 1) inputRefs.current[index - 1]?.focus() } } const handleKeyDown = (index: number, e: React.KeyboardEvent) => { if (e.key === "Backspace" && !codes[index] && index > 0) { setActiveIndex(index - 1) inputRefs.current[index - 1]?.focus() } } const handleVerify = (e: React.FormEvent) => { e.preventDefault() const code = codes.join("") if (code.length === 5) { // Handle verification logic here console.log("Verification code:", code) } } const handleResend = () => { if (timeLeft === 0) { setTimeLeft(30) setCodes(["", "", "", "", ""]) setActiveIndex(0) inputRefs.current[0]?.focus() // Handle resend logic here console.log("Resending code...") } } const formatTime = (seconds: number) => { const mins = Math.floor(seconds / 60) const secs = seconds % 60 return `${String(mins).padStart(2, "0")}:${String(secs).padStart(2, "0")}` } return (

Verification Code

We have sent a verification code sent to your email address ******230@gmail.com

{codes.map((code, index) => ( { inputRefs.current[index] = el }} type="text" inputMode="numeric" maxLength={1} value={code} onChange={(e) => handleCodeChange(index, e.target.value)} onKeyDown={(e) => handleKeyDown(index, e)} onFocus={() => setActiveIndex(index)} className={`h-14 w-14 text-center text-xl font-semibold ${ activeIndex === index ? "border-2 border-brand-500 ring-2 ring-brand-500/20" : "" }`} /> ))}
Resend code in {formatTime(timeLeft)}
) }