"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useEffect } from "react"; import { cn } from "@/lib/utils"; import { useAuth } from "@/hooks/use-auth"; import { useTotalUnread } from "@/hooks/use-total-unread"; import { LayoutDashboard, MessageSquare, Users, GitBranch, Radio, Zap, Workflow, Settings, LogOut, User, X, } from "lucide-react"; import { Avatar, AvatarFallback, AvatarImage, } from "@/components/ui/avatar"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; interface NavItem { href: string; label: string; icon: typeof LayoutDashboard; /** * When true, the nav row renders a small "Beta" chip after the label. * Purely informational — doesn't affect routing or access. */ beta?: boolean; } const navItems: NavItem[] = [ { href: "/dashboard", label: "Dashboard", icon: LayoutDashboard }, { href: "/inbox", label: "Inbox", icon: MessageSquare }, { href: "/contacts", label: "Contacts", icon: Users }, { href: "/pipelines", label: "Pipelines", icon: GitBranch }, { href: "/broadcasts", label: "Broadcasts", icon: Radio }, { href: "/automations", label: "Automations", icon: Zap }, { href: "/flows", label: "Flows", icon: Workflow, beta: true }, ]; const bottomNavItems = [ { href: "/settings", label: "Settings", icon: Settings }, ]; interface SidebarProps { /** Controlled on mobile by the Header's hamburger button. Ignored on lg+. */ open?: boolean; onClose?: () => void; } export function Sidebar({ open = false, onClose }: SidebarProps) { const pathname = usePathname(); const { profile, signOut } = useAuth(); const totalUnread = useTotalUnread(); // Close the drawer when route changes — users opened it to navigate, // so once they pick a destination the drawer should get out of the way. useEffect(() => { onClose?.(); // Only pathname drives this — onClose identity doesn't need to re-run it. // eslint-disable-next-line react-hooks/exhaustive-deps }, [pathname]); // Lock body scroll and allow Escape to close while the drawer is open on // mobile. No-ops on desktop because the sidebar isn't positioned there. useEffect(() => { if (!open) return; const prev = document.body.style.overflow; document.body.style.overflow = "hidden"; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose?.(); }; window.addEventListener("keydown", onKey); return () => { document.body.style.overflow = prev; window.removeEventListener("keydown", onKey); }; }, [open, onClose]); return ( <> {/* Backdrop — only exists on mobile and only when open. Clicking it closes the drawer. Hidden from lg+ since the sidebar is part of the main flex row there. */} {/* Main navigation */} {/* User section */}
{profile?.avatar_url ? ( ) : null} {profile?.full_name?.charAt(0)?.toUpperCase() ?? profile?.email?.charAt(0)?.toUpperCase() ?? "U"}

{profile?.full_name ?? "User"}

{profile?.email ?? ""}

} > Profile } > Settings Sign out
); }