import { Layout, Menu, Button, Typography, Space, Tag, Dropdown } from 'antd';
import type { MenuProps } from 'antd';
import {
DashboardOutlined, SettingOutlined, LogoutOutlined,
LineChartOutlined, ApartmentOutlined, TeamOutlined, TableOutlined,
UserOutlined, DownOutlined,
} from '@ant-design/icons';
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
import { useAuth } from '../../hooks/useAuth';
import { useBranding } from '../../hooks/useBranding';
import { useAppInfo } from '../../hooks/useAppInfo';
const { Header, Sider, Content, Footer } = Layout;
const { Text } = Typography;
export function AppLayout() {
const { user, logout } = useAuth();
const { branding } = useBranding();
const { isAdmin: adminMode } = useAppInfo();
const navigate = useNavigate();
const location = useLocation();
const userIsAdmin = user?.roles.includes('Admin') ?? false;
const handleLogout = async () => {
await logout();
navigate('/login', { replace: true });
};
const adminItems = adminMode
? [{ key: '/admin/customers', icon: , label: 'Customers' }]
: [{ key: '/admin/sites', icon: , label: 'Sites' }];
// Measurements page is per-customer data: only meaningful in Client mode.
// In Admin mode the equivalent is the Customer detail measurements tab.
const measurementsItem = adminMode
? []
: [{ key: '/measurements', icon: , label: 'Measurements' }];
const items = [
{ key: '/', icon: , label: 'Dashboard' },
{ key: '/dashboards', icon: , label: 'Dashboards' },
...measurementsItem,
...(userIsAdmin
? [...adminItems, { key: '/settings', icon: , label: 'Settings' }]
: []),
];
return (
{branding.logoUrl && (
)}
{branding.applicationName}
{adminMode && FLEET ADMIN}
navigate('/profile')}
onLogout={handleLogout}
/>
{branding.footerText && (
)}
);
}
function UserMenu({
displayName, onProfile, onLogout,
}: {
displayName: string;
onProfile: () => void;
onLogout: () => void;
}) {
const items: MenuProps['items'] = [
{ key: 'profile', label: 'My profile', icon: , onClick: onProfile },
{ type: 'divider' },
{ key: 'logout', label: 'Sign out', icon: , danger: true, onClick: onLogout },
];
return (
);
}