import { NavLink } from 'react-router-dom';
import {
ArrowRightLeft,
Boxes,
ChevronsLeft,
ChevronsRight,
Hand,
LayoutDashboard,
Layers,
type LucideIcon,
MapPinned,
Package,
Server,
Users as UsersIcon,
Webhook,
} from 'lucide-react';
import { cn, Button, Tooltip, TooltipContent, TooltipTrigger } from '@vector/ui';
import { useAuth } from '../../contexts/AuthContext.js';
interface NavItem {
to: string;
label: string;
icon: LucideIcon;
adminOnly?: boolean;
}
const NAV_ITEMS: NavItem[] = [
{ to: '/', label: 'Dashboard', icon: LayoutDashboard },
{ to: '/parts', label: 'Parts', icon: Package },
{ to: '/part-models', label: 'Part models', icon: Layers },
{ to: '/locations', label: 'Locations', icon: MapPinned },
{ to: '/manufacturers', label: 'Manufacturers', icon: Boxes },
{ to: '/repairs', label: 'Repairs', icon: ArrowRightLeft },
{ to: '/custody', label: 'My Custody', icon: Hand },
{ to: '/hosts', label: 'Hosts', icon: Server },
{ to: '/admin/users', label: 'Users', icon: UsersIcon, adminOnly: true },
{ to: '/admin/webhooks', label: 'Webhooks', icon: Webhook, adminOnly: true },
];
export interface SidebarProps {
collapsed: boolean;
onToggle: () => void;
}
export function Sidebar({ collapsed, onToggle }: SidebarProps) {
const { user } = useAuth();
const items = NAV_ITEMS.filter((i) => !i.adminOnly || user?.role === 'ADMIN');
return (
);
}
function NavItemLink({ item, collapsed }: { item: NavItem; collapsed: boolean }) {
const content = (
cn(
'flex items-center gap-3 rounded-md px-2.5 py-2 text-sm transition-colors',
isActive
? 'bg-accent text-accent-foreground'
: 'text-muted-foreground hover:bg-accent/60 hover:text-foreground',
collapsed && 'justify-center px-0',
)
}
>
{!collapsed && {item.label}}
);
if (!collapsed) return content;
return (
{content}
{item.label}
);
}