import React, { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { useAuthStore } from '../store/authStore' import { useSettingsStore } from '../store/settingsStore' import { useTranslation } from '../i18n' import { authApi } from '../api/client' import { Plane, Eye, EyeOff, Mail, Lock, MapPin, Calendar, Package, User, Globe } from 'lucide-react' export default function LoginPage() { const { t, language } = useTranslation() const [mode, setMode] = useState('login') // 'login' | 'register' const [username, setUsername] = useState('') const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [showPassword, setShowPassword] = useState(false) const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState('') const [appConfig, setAppConfig] = useState(null) const { login, register } = useAuthStore() const { setLanguageLocal } = useSettingsStore() const navigate = useNavigate() useEffect(() => { authApi.getAppConfig?.().catch(() => null).then(config => { if (config) { setAppConfig(config) if (!config.has_users) setMode('register') } }) }, []) const handleSubmit = async (e) => { e.preventDefault() setError('') setIsLoading(true) try { if (mode === 'register') { if (!username.trim()) { setError('Username is required'); setIsLoading(false); return } if (password.length < 6) { setError('Password must be at least 6 characters'); setIsLoading(false); return } await register(username, email, password) } else { await login(email, password) } navigate('/dashboard') } catch (err) { setError(err.message || t('login.error')) } finally { setIsLoading(false) } } const showRegisterOption = appConfig?.allow_registration || !appConfig?.has_users const inputBase = { width: '100%', padding: '11px 12px 11px 40px', border: '1px solid #e5e7eb', borderRadius: 12, fontSize: 14, fontFamily: 'inherit', outline: 'none', color: '#111827', background: 'white', boxSizing: 'border-box', transition: 'border-color 0.15s', } return (
{/* Sprach-Toggle oben rechts */} {/* Left — branding */}
{/* Logo */}
NOMAD

{t('login.tagline')}

{t('login.description')}

{[ { Icon: MapPin, label: t('login.features.places') }, { Icon: Calendar, label: t('login.features.schedule') }, { Icon: Package, label: t('login.features.packing') }, ].map(({ Icon, label }) => (
{label}
))}
{/* Right — form */}
{/* Mobile logo */}
NOMAD

{mode === 'register' ? (!appConfig?.has_users ? t('login.createAdmin') : t('login.createAccount')) : t('login.title')}

{mode === 'register' ? (!appConfig?.has_users ? t('login.createAdminHint') : t('login.createAccountHint')) : t('login.subtitle')}

{error && (
{error}
)} {/* Username (register only) */} {mode === 'register' && (
setUsername(e.target.value)} required placeholder="admin" style={inputBase} onFocus={e => e.target.style.borderColor = '#111827'} onBlur={e => e.target.style.borderColor = '#e5e7eb'} />
)} {/* Email */}
setEmail(e.target.value)} required placeholder="deine@email.de" style={inputBase} onFocus={e => e.target.style.borderColor = '#111827'} onBlur={e => e.target.style.borderColor = '#e5e7eb'} />
{/* Password */}
setPassword(e.target.value)} required placeholder="••••••••" style={{ ...inputBase, paddingRight: 44 }} onFocus={e => e.target.style.borderColor = '#111827'} onBlur={e => e.target.style.borderColor = '#e5e7eb'} />
{/* Toggle login/register */} {showRegisterOption && appConfig?.has_users && (

{mode === 'login' ? t('login.noAccount') + ' ' : t('login.hasAccount') + ' '}

)}
) }