import { useState, useMemo } from "react"; import { Link, useLocation } from "@remix-run/react"; import { Badge } from "~/components/ui/badge"; import { Button } from "~/components/ui/button"; import { ScrollArea } from "~/components/ui/scroll-area"; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "~/components/ui/collapsible"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "~/components/ui/tooltip"; import { LayoutDashboard, Recycle, Users, FileText, Settings, MapPin, UserCheck, Newspaper, HelpCircle, ChevronDown, X } from "lucide-react"; import { cn } from "~/lib/utils"; interface SidebarProps { isOpen: boolean; isCollapsed: boolean; isHovered: boolean; isMobile: boolean; onClose: () => void; onMouseEnter: () => void; onMouseLeave: () => void; } interface MenuItem { title: string; icon?: React.ReactNode; href?: string; badge?: string; badgeVariant?: "pro" | "new" | "urgent"; children?: MenuItem[]; } const menuItems: MenuItem[] = [ { title: "Dashboard", icon: , href: "/sys-rijig-adminpanel/dashboard" }, { title: "Data Sampah", icon: , href: "/sys-rijig-adminpanel/dashboard/waste" }, { title: "Manajemen User", icon: , children: [ { title: "Verifikasi User", href: "/sys-rijig-adminpanel/dashboard/users", badge: "urgent" }, { title: "Masyarakat", href: "/sys-rijig-adminpanel/masyarakat" }, { title: "Pengepul", href: "/sys-rijig-adminpanel/pengepul" }, { title: "Pengelola", href: "/sys-rijig-adminpanel/pengelola" } ] }, { title: "Artikel & Blog", icon: , href: "/sys-rijig-adminpanel/dashboard/artikel-blog" }, { title: "Tips & Panduan", icon: , href: "/sys-rijig-adminpanel/dashboard/tips-panduan" }, { title: "Area Coverage", icon: , href: "/sys-rijig-adminpanel/dashboard/areacoverage" }, { title: "Pengaturan", icon: , href: "/sys-rijig-adminpanel/dashboard/pengaturan" } ]; function MenuItemComponent({ item, isCollapsed, isHovered }: { item: MenuItem; isCollapsed: boolean; isHovered: boolean; }) { const location = useLocation(); const pathname = location.pathname; const [isOpen, setIsOpen] = useState(false); const hasChildren = item.children && item.children.length > 0; const showText = !isCollapsed || isHovered; // Check if any child is active const isChildActive = useMemo(() => { if (!hasChildren) return false; return item.children!.some((child) => child.href === pathname); }, [hasChildren, item.children, pathname]); // Auto open if child is active useMemo(() => { if (isChildActive && !isOpen) { setIsOpen(true); } }, [isChildActive, isOpen]); // For collapsed state without hover, show tooltip if (isCollapsed && !isHovered) { return (
  • {item.title}

  • ); } if (hasChildren) { return (
  • {showText && ( {item.children?.map((child, childIndex) => { const isActive = pathname === child.href; return ( {isActive && (
    )} {child.title} {child.badge && ( {child.badge} )} ); })} )}
  • ); } // Single menu item (no children) const isActive = pathname === item.href; return (
  • ); } export function AdminSidebar({ isOpen, isCollapsed, isHovered, isMobile, onClose, onMouseEnter, onMouseLeave }: SidebarProps) { const sidebarWidth = isCollapsed && !isHovered ? "w-20" : "w-72"; const showText = !isCollapsed || isHovered; return ( ); }