import React, { useState } from 'react'; import { X, User, Sparkles } from 'lucide-react'; import { useI18n } from '../context/I18nContext'; interface UsernameModalProps { isOpen: boolean; onSubmit: (username: string) => Promise; } export const UsernameModal: React.FC = ({ isOpen, onSubmit }) => { const { t } = useI18n(); const [username, setUsername] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); if (!isOpen) return null; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); const trimmed = username.trim(); if (trimmed.length < 2) { setError(t('usernameMinLength')); return; } if (!/^[a-zA-Z0-9_-]+$/.test(trimmed)) { setError(t('usernameInvalidChars')); return; } setIsLoading(true); try { await onSubmit(trimmed); } catch (err) { setError(err instanceof Error ? err.message : t('failedToSetUsername')); } finally { setIsLoading(false); } }; return (
{/* Backdrop */}
{/* Modal */}
{/* Header gradient */}
{/* Logo */}
{/* Title */}

{t('welcomeTitle')}

{t('welcomeSubtitle')}

{/* Form */}
setUsername(e.target.value)} placeholder={t('enterYourName')} className="w-full pl-10 pr-4 py-3 bg-zinc-800 border border-zinc-700 rounded-xl text-white placeholder-zinc-500 focus:outline-none focus:ring-2 focus:ring-pink-500 focus:border-transparent transition-all" autoFocus disabled={isLoading} />
{error && (

{error}

)}
{/* Footer */}

{t('yourMusicYourWay')}

); };