import { useState } from 'react' import { Navigate } from 'react-router' import { Box, Button, Card, CardContent, Chip, CircularProgress, Divider, TextField, Typography, } from '@mui/material' import { Building2 } from 'lucide-react' import { useLogin, useSwitchDemoRole } from '../../hooks/useAuth' import { useSessionStore } from '../../stores/sessionStore' import { UserRole } from '../../domain/enums' const DEMO_ROLES: { role: UserRole; label: string; description: string }[] = [ { role: UserRole.PROPERTY_MANAGER, label: 'Verwaltung', description: 'Portfolio verwalten + Markt durchsuchen' }, { role: UserRole.DEMAND_USER, label: 'Bürosuche', description: 'Nur Marktsuche — kein Portfolio' }, ] export default function LoginScreen() { const { isAuthenticated } = useSessionStore() const loginMutation = useLogin() const switchDemoRoleMutation = useSwitchDemoRole() const [email, setEmail] = useState('admin@ideal-sharing.ch') const [password, setPassword] = useState('') const [error, setError] = useState(null) if (isAuthenticated) { return } const loading = loginMutation.isPending || switchDemoRoleMutation.isPending function handleLogin(e: React.FormEvent) { e.preventDefault() if (!email) { setError('Bitte E-Mail-Adresse eingeben.') return } setError(null) loginMutation.mutate( { email, password }, { onError: () => { setError('Anmeldung fehlgeschlagen. Bitte erneut versuchen.') }, }, ) } function handleDemoLogin(role: UserRole) { switchDemoRoleMutation.mutate(role) } return ( {/* Branding */} Property Match Decision Intelligence {/* Login card */} Anmelden Melden Sie sich mit Ihren Zugangsdaten an. setEmail(e.target.value)} autoComplete="email" required /> setPassword(e.target.value)} autoComplete="current-password" helperText="Im Demo-Modus wird jedes Passwort akzeptiert." /> {error && ( {error} )} {/* Demo access */} Demo-Zugänge {DEMO_ROLES.map(({ role, label, description }) => ( handleDemoLogin(role)} sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', px: 1.5, py: 1, borderRadius: 1, border: '1px solid #e2e8f0', cursor: 'pointer', transition: 'border-color 0.15s', '&:hover': { borderColor: '#152642', bgcolor: 'rgba(30,58,95,0.03)' }, }} > {label} {description} ))} ) }