'use client' import * as React from 'react' import { Loader2 } from 'lucide-react' import { useT } from '@open-mercato/shared/lib/i18n/context' import { Button } from '@open-mercato/ui/primitives/button' import { Input } from '@open-mercato/ui/primitives/input' import { Label } from '@open-mercato/ui/primitives/label' type OtpEmailChallengeVerifyProps = { onVerify: (payload: { code: string }) => Promise onResend?: () => Promise submitLabel: string } export default function OtpEmailChallengeVerify({ onVerify, onResend, submitLabel, }: OtpEmailChallengeVerifyProps) { const t = useT() const [code, setCode] = React.useState('') const [submitting, setSubmitting] = React.useState(false) const [resending, setResending] = React.useState(false) const canSubmit = code.trim().length >= 6 && !submitting const handleSubmit = React.useCallback(async (event: React.FormEvent) => { event.preventDefault() if (!canSubmit) return setSubmitting(true) try { await onVerify({ code: code.trim() }) setCode('') } finally { setSubmitting(false) } }, [canSubmit, code, onVerify]) const handleResend = React.useCallback(async () => { if (!onResend || resending) return setResending(true) try { await onResend() } finally { setResending(false) } }, [onResend, resending]) return (

{t('security.login.mfaChallenge.otpEmail.title', 'Two-factor authentication')}

{t( 'security.login.mfaChallenge.otpEmail.description', 'Enter the 6-digit code sent to your email address.', )}

setCode(event.target.value)} placeholder={t('security.login.mfaChallenge.otpEmail.placeholder', 'XXXXXX')} autoComplete="one-time-code" inputMode="numeric" maxLength={6} className="h-10 border-slate-700 bg-slate-950 text-slate-100 placeholder:text-slate-500" />
{onResend ? ( ) : null}
) }