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 { LoginCredentials } from '../../domain/types'; interface Props { onRegisterClick?: () => void; enableRegistration?: boolean; } export default function LoginForm({ onRegisterClick, enableRegistration }: Props) { const [credentials, setCredentials] = useState({ username: '', password: '' }); const [showPassword, setShowPassword] = useState(false); const [error, setError] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const { login } = useAuthStore(); const { lang } = useLang(); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); setError(''); setIsSubmitting(true); try { await login(credentials.username, credentials.password); } catch (err: unknown) { setError(err instanceof Error ? err.message : 'Ошибка'); setIsSubmitting(false); } }; return ( <> {error && ( {error} )}
person 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" />
lock setCredentials({ ...credentials, password: e.target.value })} placeholder={lang === 'ru' ? '••••••••' : '••••••••'} 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="current-password" />
{enableRegistration && onRegisterClick && (

{lang === 'ru' ? 'Нет аккаунта?' : "New to Knot?"}

)} ); }