import { useState } from 'react'; import { NavLink, useNavigate, useLocation } from 'react-router-dom'; import { useQuery } from '@tanstack/react-query'; import { LayoutDashboard, CheckSquare, Calendar, Bell, FolderKanban, Users, MapPin, Settings, ChevronLeft, ChevronRight, ChevronDown, X, LogOut, } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useAuth } from '@/hooks/useAuth'; import { Button } from '@/components/ui/button'; import api from '@/lib/api'; import type { Project } from '@/types'; const navItems = [ { to: '/dashboard', icon: LayoutDashboard, label: 'Dashboard' }, { to: '/todos', icon: CheckSquare, label: 'Todos' }, { to: '/calendar', icon: Calendar, label: 'Calendar' }, { to: '/reminders', icon: Bell, label: 'Reminders' }, { to: '/people', icon: Users, label: 'People' }, { to: '/locations', icon: MapPin, label: 'Locations' }, ]; interface SidebarProps { collapsed: boolean; onToggle: () => void; mobileOpen: boolean; onMobileClose: () => void; } export default function Sidebar({ collapsed, onToggle, mobileOpen, onMobileClose }: SidebarProps) { const navigate = useNavigate(); const location = useLocation(); const { logout } = useAuth(); const [projectsExpanded, setProjectsExpanded] = useState(false); const { data: trackedProjects } = useQuery({ queryKey: ['projects', 'tracked'], queryFn: async () => { const { data } = await api.get('/projects?tracked=true'); return data; }, staleTime: 60_000, select: (data) => data.map(({ id, name }) => ({ id, name })), }); const handleLogout = async () => { await logout(); navigate('/login'); }; const isProjectsActive = location.pathname.startsWith('/projects'); const showExpanded = !collapsed || mobileOpen; const navLinkClass = ({ isActive }: { isActive: boolean }) => cn( 'flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-all duration-200', isActive ? 'bg-accent/15 text-accent border-l-2 border-accent' : 'text-muted-foreground hover:bg-accent/10 hover:text-accent border-l-2 border-transparent' ); const projectsSection = (
{ navigate('/projects'); if (mobileOpen) onMobileClose(); }} /> {showExpanded && ( <> { navigate('/projects'); if (mobileOpen) onMobileClose(); }} > Projects {trackedProjects && trackedProjects.length > 0 && ( )} )}
{showExpanded && projectsExpanded && trackedProjects && trackedProjects.length > 0 && (
{trackedProjects.map((project) => { const isActive = location.pathname === `/projects/${project.id}`; return ( ); })}
)}
); const sidebarContent = ( <>
{!collapsed &&

UMBRA

}
{showExpanded && Settings}
); return ( <> {/* Desktop sidebar */} {/* Mobile overlay */} {mobileOpen && (
)} ); }