'use client'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { ChevronRight, FileText, Heart, LockKeyhole, LogOut, ShieldCheck, Smartphone, UserRound } from 'lucide-react'; import { AdminBadge } from '@/components/id/admin-badge'; import { useAuth } from '@/components/id/auth-provider'; import { useAvatarUrl } from '@/hooks/use-avatar-url'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { cn } from '@/lib/utils'; function maskPhone(phone?: string | null) { if (!phone) return null; const digits = phone.replace(/\D/g, ''); if (digits.length < 10) return phone; return `+${digits.slice(0, 1)} ${digits.slice(1, 4)} ***-**-${digits.slice(-2)}`; } const menuItems = [ { href: '/data', label: 'Личные данные', subtitle: 'ФИО, день рождения, пол', icon: UserRound }, { href: '/security', label: 'Телефон и безопасность', subtitle: 'PIN, пароль, устройства', icon: Smartphone }, { href: '/documents', label: 'Документы', subtitle: 'Паспорт, права, загран', icon: FileText }, { href: '/family', label: 'Семья', subtitle: 'Участники и доступ', icon: Heart }, { href: '/security', label: 'Защита аккаунта', subtitle: 'Способы входа и сессии', icon: LockKeyhole } ]; export function UserMenu({ className }: { className?: string }) { const router = useRouter(); const { user, token, logout } = useAuth(); const { avatarUrl } = useAvatarUrl(user?.id, user?.hasAvatar, token); if (!user) return null; const contactLine = [maskPhone(user.phone), user.username ?? user.email].filter(Boolean).join(' · '); const initials = user.displayName .split(' ') .map((part) => part[0]) .join('') .slice(0, 2) .toUpperCase(); return (
{avatarUrl ? : null} {initials}

{user.displayName}

{contactLine || 'Контакты не указаны'}

{menuItems.map((item) => (
{item.label}
{item.subtitle}
))} {user.canAccessAdmin ? (
Админ-панель
Пользователи, OAuth и настройки
) : null}
); }