import React from 'react'; import { useNavigate } from 'react-router-dom'; import { HelpCircle, LogOut, Monitor, Moon, Settings, Sun, User, Languages, CreditCard } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuItem, DropdownMenuGroup, DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuSubContent, } from '@/components/ui/dropdown-menu'; import { Avatar, AvatarFallback } from '@/components/ui/avatar'; import { Button } from '@/components/ui/button'; import { useAuth } from '../auth/context'; import { ADMIN_FAQ_PATH, ADMIN_PROFILE_PATH, ADMIN_SETTINGS_PATH, ADMIN_BILLING_PATH } from '../constants'; import { useAppearance } from '@/hooks/use-appearance'; import { SUPPORTED_LANGUAGES, getCurrentLocale, switchLocale, type SupportedLocale } from '../lib/locale'; export function UserMenu() { const { user, logout } = useAuth(); const { appearance, updateAppearance } = useAppearance(); const navigate = useNavigate(); const { t } = useTranslation('common'); const [pendingLocale, setPendingLocale] = React.useState(null); const currentLocale = getCurrentLocale(); const isMember = user?.role === 'member'; const initials = React.useMemo(() => { if (user?.name) { return user.name .split(' ') .filter(Boolean) .slice(0, 2) .map((part) => part[0]) .join('') .toUpperCase(); } if (user?.email) { return user.email.charAt(0).toUpperCase(); } return 'TU'; }, [user?.name, user?.email]); const changeLanguage = React.useCallback(async (locale: SupportedLocale) => { if (locale === currentLocale) { return; } setPendingLocale(locale); try { await switchLocale(locale); } finally { setPendingLocale(null); } }, [currentLocale]); const changeAppearance = React.useCallback( (mode: 'light' | 'dark' | 'system') => { updateAppearance(mode); }, [updateAppearance] ); const goTo = React.useCallback((path: string) => navigate(path), [navigate]); return (

{user?.name ?? t('user.unknown')}

{user?.email ?

{user.email}

: null}
goTo(ADMIN_PROFILE_PATH)}> {t('navigation.profile', { defaultValue: 'Profil' })} {!isMember && ( <> goTo(ADMIN_SETTINGS_PATH)}> {t('navigation.settings', { defaultValue: 'Einstellungen' })} goTo(ADMIN_BILLING_PATH)}> {t('navigation.billing', { defaultValue: 'Billing' })} )} {t('app.languageSwitch')} {SUPPORTED_LANGUAGES.map(({ code, labelKey }) => ( { event.preventDefault(); changeLanguage(code); }} disabled={pendingLocale === code} > {t(labelKey)} {currentLocale === code ? {t('app.languageActive', { defaultValue: 'Aktiv' })} : null} ))} {appearance === 'dark' ? : appearance === 'light' ? : } {t('app.theme', { defaultValue: 'Darstellung' })} {(['light', 'dark', 'system'] as const).map((mode) => ( changeAppearance(mode)}> {mode === 'light' ? : mode === 'dark' ? : } {t(`app.theme_${mode}`, { defaultValue: mode })} ))} goTo(ADMIN_FAQ_PATH)}> {t('app.help', { defaultValue: 'FAQ & Hilfe' })} { event.preventDefault(); logout(); }} > {t('app.logout', { defaultValue: 'Abmelden' })}
); }