import React, { useState, FormEvent } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Eye, EyeOff, ArrowRight } from 'lucide-react'; import { useAuthStore } from '../../application/authStore'; import { useLang } from '../../../../core/infrastructure/i18n'; import type { RegisterCredentials } from '../../domain/types'; interface Props { onLoginClick: () => void; enableRegistration?: boolean; } export default function RegisterForm({ onLoginClick, enableRegistration }: Props) { const [credentials, setCredentials] = useState({ username: '', displayName: '', password: '', bio: '' }); const [showPassword, setShowPassword] = useState(false); const [error, setError] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const { register } = useAuthStore(); const { lang } = useLang(); if (!enableRegistration) return null; const handleSubmit = async (e: FormEvent) => { e.preventDefault(); setError(''); setIsSubmitting(true); try { await register(credentials.username, credentials.displayName || credentials.username, credentials.password, credentials.bio); } catch (err: unknown) { setError(err instanceof Error ? err.message : 'Ошибка'); setIsSubmitting(false); } }; return ( <> {error && ( {error} )}
setCredentials({ ...credentials, username: e.target.value.replace(/[^a-zA-Z0-9_]/g, '') })} placeholder="username" className="w-full px-4 py-3.5 rounded-xl bg-[#18181b] border border-white/5 text-white placeholder-zinc-600 focus:border-[#9b66ff]/50 focus:bg-[#1f1f22] transition-colors outline-none text-[15px]" required autoFocus autoComplete="off" />
setCredentials({ ...credentials, displayName: e.target.value })} placeholder={lang === 'ru' ? 'Ваше имя (любой язык)' : 'Your name'} className="w-full px-4 py-3.5 rounded-xl bg-[#18181b] border border-white/5 text-white placeholder-zinc-600 focus:border-[#9b66ff]/50 focus:bg-[#1f1f22] transition-colors outline-none text-[15px]" />
setCredentials({ ...credentials, password: e.target.value })} placeholder={lang === 'ru' ? 'Введите пароль' : 'Enter password'} className="w-full px-4 py-3.5 rounded-xl bg-[#18181b] border border-white/5 text-white placeholder-zinc-600 focus:border-[#9b66ff]/50 focus:bg-[#1f1f22] transition-colors pr-12 outline-none text-[15px]" required autoComplete="new-password" minLength={8} />

{lang === 'ru' ? 'Минимум 8 символов, буквы и цифры' : 'Minimum 8 characters, letters and numbers'}

setCredentials({ ...credentials, bio: e.target.value })} placeholder={lang === 'ru' ? 'Расскажите о себе (необязательно)' : 'Tell about yourself (optional)'} className="w-full px-4 py-3.5 rounded-xl bg-[#18181b] border border-white/5 text-white placeholder-zinc-600 focus:border-[#9b66ff]/50 focus:bg-[#1f1f22] transition-colors outline-none text-[15px]" />
{isSubmitting ? (
) : ( <> {lang === 'ru' ? 'Создать аккаунт' : 'Create account'} )} {enableRegistration && (

{lang === 'ru' ? 'Уже есть аккаунт?' : 'Already have an account?'}

)} ); }