import { useState } from 'react' import { ApartmentOutlined, BarChartOutlined, CameraOutlined, LogoutOutlined, MenuOutlined, OrderedListOutlined, UserOutlined, } from '@ant-design/icons' import { Avatar, Button, Drawer, Layout, Menu, Result, Space, Tag, Typography } from 'antd' import { Outlet, useLocation, useNavigate } from 'react-router-dom' import { ROLE_MANAGE_AREA, ROLE_MANAGE_ATTRACTION } from '@/auth/roles' import { useAuth } from '@/auth/AuthContext' import { useIsMobile } from '@/hooks/useIsMobile' const { Header, Sider, Content } = Layout const ROLE_LABELS: Record = { [ROLE_MANAGE_AREA]: 'управление зонами', [ROLE_MANAGE_ATTRACTION]: 'управление контентом', } export function AdminLayout() { const { email, roles, logout } = useAuth() const location = useLocation() const navigate = useNavigate() const isMobile = useIsMobile() const [menuOpen, setMenuOpen] = useState(false) const hasManageArea = roles.includes(ROLE_MANAGE_AREA) const hasManageAttraction = roles.includes(ROLE_MANAGE_ATTRACTION) // При переходе десктоп↔мобильный открытый Drawer теряет смысл — сбрасываем // во время рендера (паттерн «adjust state when props change» из доков React). const [wasMobile, setWasMobile] = useState(isMobile) if (wasMobile !== isMobile) { setWasMobile(isMobile) setMenuOpen(false) } if (!hasManageArea && !hasManageAttraction) { return ( } onClick={logout}> Выйти } /> ) } const menuItems = [ hasManageArea && { key: '/areas', icon: , label: 'Зоны' }, hasManageAttraction && { key: '/attractions', icon: , label: 'Достопримечательности', }, hasManageArea && { key: '/sets', icon: , label: 'Наборы', }, hasManageArea && { key: '/visits', icon: , label: 'Визиты' }, ].filter(Boolean) as { key: string; icon: React.ReactNode; label: string }[] const selectedKey = '/' + (location.pathname.split('/')[1] ?? '') const menu = ( { navigate(key) setMenuOpen(false) }} style={{ borderRight: 0, paddingTop: 8 }} /> ) const roleTags = ( {roles .filter((role) => ROLE_LABELS[role]) .map((role) => ( {ROLE_LABELS[role]} ))} ) return (
{isMobile ? ( <> )}
{isMobile ? ( setMenuOpen(false)} styles={{ body: { padding: 0 } }} >
} /> {email}
{roleTags}
{menu}
) : ( {menu} )}
) }