import type { ReactNode } from "react"; import { NavLink } from "@/lib/router"; import type { IssueNavigationPrefetchHandlers } from "@/hooks/useIssueNavigationPrefetch"; import { SIDEBAR_SCROLL_RESET_STATE } from "../lib/navigation-scroll"; import { cn } from "../lib/utils"; import { useSidebar } from "../context/SidebarContext"; import type { LucideIcon } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { TruncatedText } from "./TruncatedText"; interface SidebarNavItemProps { to: string; label: string; icon?: LucideIcon; /** * Pre-rendered icon element for rows whose icon isn't a plain Lucide * component (e.g. the agent rows' `AgentIcon`). Takes precedence over `icon`; * the caller supplies a 16px icon to fit the shared navigation slot. */ iconNode?: ReactNode; end?: boolean; className?: string; labelClassName?: string; badge?: number; badgeTone?: "default" | "danger" | "warning"; badgeLabel?: string; textBadge?: string; textBadgeTone?: "default" | "amber"; alert?: boolean; liveCount?: number; /** * Overrides NavLink's own route matching for rows whose active state is * computed externally (agent rows match `/agents/:ref` across tab suffixes). */ active?: boolean; /** Rendered after the label, before the right-aligned status cluster. */ trailing?: ReactNode; /** Rendered inside the right-aligned status cluster, before the live dot. */ liveAccessory?: ReactNode; /** Extra link handlers, such as a task's open-intent prefetch. */ linkHandlers?: Partial; } export function SidebarNavItem({ to, label, icon: Icon, iconNode, end, className, labelClassName, badge, badgeTone = "default", badgeLabel, textBadge, textBadgeTone = "default", alert = false, liveCount, active, trailing, liveAccessory, linkHandlers, }: SidebarNavItemProps) { const { isMobile, setSidebarOpen } = useSidebar(); const hasBadge = badge != null && badge > 0; const hasLive = liveCount != null && liveCount > 0; const showIconSlot = Boolean(iconNode || Icon || alert); return ( { if (isMobile) setSidebarOpen(false); }} className={({ isActive }) => cn( // One rhythm and one inset pill highlight: mx-2 floats the row off // the sidebar edges, rounded-lg matches the card anchor, px-2 gives // the icon breathing room inside the pill. Rows with hover menus // (agents/projects) reserve extra right padding via className. "flex items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 text-left text-(length:--text-compact) font-medium transition-colors", (active ?? isActive) ? "bg-sidebar-accent text-sidebar-accent-foreground" : "text-foreground/80 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground", className, ) } > {showIconSlot ? ( {iconNode ?? (Icon ? : null)} {alert && ( ) : null} {label} {trailing} {textBadge && ( {textBadge} )} {(hasLive || liveAccessory) && ( {liveAccessory} {hasLive && ( <> {liveCount} live )} )} {hasBadge && ( {badge} )} ); }