import React, { useRef, useState } from 'react'; import { ArrowRight, KeyRound, User, Languages } from 'lucide-react'; interface CodeInputProps { onComplete: (code: string, name?: string, language?: string) => void; isLoading?: boolean; } const LANGUAGES = [ { label: 'No Dubbing (Original)', value: '' }, { label: 'Spanish', value: 'Spanish' }, { label: 'French', value: 'French' }, { label: 'German', value: 'German' }, { label: 'Hindi', value: 'Hindi' }, { label: 'Japanese', value: 'Japanese' }, { label: 'Chinese (Mandarin)', value: 'Chinese' }, { label: 'Portuguese', value: 'Portuguese' }, ]; export const CodeInput: React.FC = ({ onComplete, isLoading }) => { const [code, setCode] = useState(new Array(6).fill('')); const [name, setName] = useState(''); const [language, setLanguage] = useState(''); const inputsRef = useRef<(HTMLInputElement | null)[]>([]); const handleChange = (index: number, value: string) => { if (!/^\d*$/.test(value)) return; const newCode = [...code]; // Take only the last character if user somehow pastes or types multiple newCode[index] = value.slice(-1); setCode(newCode); if (value && index < 5) { inputsRef.current[index + 1]?.focus(); } }; const handleKeyDown = (index: number, e: React.KeyboardEvent) => { if (e.key === 'Backspace' && !code[index] && index > 0) { inputsRef.current[index - 1]?.focus(); } }; const handlePaste = (e: React.ClipboardEvent) => { e.preventDefault(); const pastedData = e.clipboardData.getData('text').replace(/\D/g, '').split(''); if (pastedData.length > 0) { const newCode = [...code]; pastedData.slice(0, 6).forEach((digit, i) => { newCode[i] = digit; }); setCode(newCode); const lastIndex = Math.min(pastedData.length - 1, 5); inputsRef.current[lastIndex]?.focus(); } }; const handleSubmit = (e?: React.FormEvent) => { e?.preventDefault(); const codeStr = code.join(''); if (codeStr.length === 6) { onComplete(codeStr, name || 'Guest', language); } }; return (

Connect with Code

Enter details to join the secure channel.

setName(e.target.value)} placeholder="Your Name (Optional)" className="w-full bg-zinc-900/50 border-2 border-zinc-800 text-white pl-11 pr-4 py-3.5 rounded-xl focus:outline-none focus:border-cyan-500/50 focus:bg-zinc-900/80 transition-all placeholder:text-zinc-600" />
{code.map((digit, idx) => ( inputsRef.current[idx] = el} type="text" inputMode="numeric" maxLength={1} autoFocus={idx === 0} value={digit} onChange={(e) => handleChange(idx, e.target.value)} onKeyDown={(e) => handleKeyDown(idx, e)} disabled={isLoading} className={`w-10 h-12 sm:w-12 sm:h-14 text-center text-xl sm:text-2xl font-mono font-bold rounded-xl border-2 transition-all duration-200 outline-none ${digit ? 'border-cyan-500 bg-cyan-950/30 text-cyan-100 shadow-[0_0_15px_-3px_rgba(6,182,212,0.3)]' : 'border-zinc-800 bg-zinc-900/50 text-zinc-500 focus:border-zinc-600 focus:bg-zinc-900' } disabled:opacity-50 disabled:cursor-not-allowed `} /> ))}
); };