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} )}
alternate_email setCredentials({ ...credentials, username: e.target.value.replace(/[^a-zA-Z0-9_]/g, '') })} placeholder="username" className="w-full pl-12 pr-4 py-4 rounded-2xl bg-surface-container-highest/60 text-on-surface placeholder-on-surface-variant/20 border-none focus:ring-2 focus:ring-primary/20 transition-all outline-none text-[15px]" required autoFocus autoComplete="off" />
face setCredentials({ ...credentials, displayName: e.target.value })} placeholder={lang === 'ru' ? 'Ваше имя' : 'Your name'} className="w-full pl-12 pr-4 py-4 rounded-2xl bg-surface-container-highest/60 text-on-surface placeholder-on-surface-variant/20 border-none focus:ring-2 focus:ring-primary/20 transition-all outline-none text-[15px]" />
lock_open setCredentials({ ...credentials, password: e.target.value })} placeholder="••••••••" className="w-full pl-12 pr-12 py-4 rounded-2xl bg-surface-container-highest/60 text-on-surface placeholder-on-surface-variant/20 border-none focus:ring-2 focus:ring-primary/20 transition-all outline-none text-[15px]" required autoComplete="new-password" minLength={8} />

{lang === 'ru' ? '8+ символов, любые знаки' : '8+ characters required'}

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]" />
{enableRegistration && (

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

)} ); }