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 { Separator } from "~/components/ui/separator"; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "~/components/ui/collapsible"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "~/components/ui/tooltip"; import { LayoutDashboard, Recycle, Users, TrendingUp, FileText, CreditCard, BarChart3, Settings, MessageCircle, MapPin, Package, DollarSign, UserCheck, Building2, Newspaper, HelpCircle, Bell, Shield, 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: , children: [ { title: "Overview", href: "/sys-rijig-adminpanel/dashboard" }, { title: "Analytics", href: "/admin/analytics" }, { title: "Statistik Sampah", href: "/admin/waste-stats", badge: "new" }, { title: "Laporan Harian", href: "/admin/daily-reports" } ] }, { title: "Data Sampah", icon: , children: [ { title: "Jenis Sampah", href: "/sys-rijig-adminpanel/dashboard/waste" }, { title: "Harga Sampah", href: "/admin/waste-prices" }, { title: "Volume Sampah", href: "/admin/waste-volume" }, { title: "Tracking Sampah", href: "/admin/waste-tracking", badge: "new" }, { title: "Kualitas Sampah", href: "/admin/waste-quality" } ] }, { title: "Manajemen User", icon: , children: [ { title: "Masyarakat", href: "/admin/users/community" }, { title: "Pengepul", href: "/admin/users/collectors" }, { title: "Pengelola Daur Ulang", href: "/admin/users/recyclers" }, { title: "Verifikasi User", href: "/sys-rijig-adminpanel/dashboard/users", badge: "urgent" }, { title: "Rating & Review", href: "/admin/users/reviews" } ] }, { title: "Transaksi", icon: , children: [ { title: "Semua Transaksi", href: "/admin/transactions/all" }, { title: "Pembayaran Pending", href: "/admin/transactions/pending", badge: "urgent" }, { title: "Riwayat Pembayaran", href: "/admin/transactions/history" }, { title: "Komisi & Fee", href: "/admin/transactions/commission" }, { title: "Laporan Keuangan", href: "/admin/transactions/financial-report" } ] } ]; const contentMenuItems: MenuItem[] = [ { title: "Content Management", icon: , children: [ { title: "Artikel & Blog", href: "/sys-rijig-adminpanel/dashboard/artikel-blog" }, { title: "Tips & Panduan", href: "/sys-rijig-adminpanel/dashboard/tips-panduan" }, { title: "FAQ", href: "/admin/content/faq" }, { title: "Pengumuman", href: "/admin/content/announcements", badge: "new" }, { title: "Testimoni", href: "/admin/content/testimonials" } ] }, { title: "Lokasi & Mapping", icon: , children: [ { title: "Peta Pengepul", href: "/admin/mapping/collectors" }, { title: "Area Coverage", href: "/sys-rijig-adminpanel/dashboard/areacoverage" }, { title: "Titik Pengumpulan", href: "/admin/mapping/collection-points" }, { title: "Rute Optimal", href: "/admin/mapping/routes", badge: "new" } ] }, { title: "Notifikasi", icon: , children: [ { title: "Push Notifications", href: "/admin/notifications/push" }, { title: "Email Broadcast", href: "/admin/notifications/email" }, { title: "SMS Gateway", href: "/admin/notifications/sms" }, { title: "Template Pesan", href: "/admin/notifications/templates" } ] } ]; const analyticsMenuItems: MenuItem[] = [ { title: "Reports & Analytics", icon: , children: [ { title: "Laporan Bulanan", href: "/admin/reports/monthly" }, { title: "Performa Pengepul", href: "/admin/reports/collector-performance" }, { title: "Tren Harga", href: "/admin/reports/price-trends" }, { title: "Dampak Lingkungan", href: "/admin/reports/environmental-impact", badge: "new" }, { title: "ROI Analysis", href: "/admin/reports/roi-analysis" } ] }, { title: "Partner & Kerjasama", icon: , children: [ { title: "Bank Sampah", href: "/admin/partners/waste-banks" }, { title: "Industri Daur Ulang", href: "/admin/partners/recycling-industry" }, { title: "Pemerintah Daerah", href: "/admin/partners/government" }, { title: "NGO & Komunitas", href: "/admin/partners/ngo-community" } ] }, { title: "Support & Help", icon: , children: [ { title: "Tiket Support", href: "/admin/support/tickets", badge: "urgent" }, { title: "Live Chat", href: "/admin/support/chat" }, { title: "Knowledge Base", href: "/admin/support/knowledge-base" }, { title: "Training Materials", href: "/admin/support/training" } ] }, { title: "Pengaturan", icon: , children: [ { title: "Konfigurasi Sistem", href: "/sys-rijig-adminpanel/dashboard/pengaturan" }, { title: "Pengaturan Harga", href: "/admin/settings/pricing" }, { title: "Role & Permission", href: "/admin/settings/roles", badge: "pro" }, { title: "Backup & Restore", href: "/admin/settings/backup" }, { title: "API Management", href: "/admin/settings/api", badge: "pro" } ] } ]; function MenuSection({ title, items, isCollapsed, isHovered }: { title: string; items: MenuItem[]; isCollapsed: boolean; isHovered: boolean; }) { const showText = !isCollapsed || isHovered; return (
{showText && (

{title}

)}
    {items.map((item, index) => ( ))}
); } 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 ( ); }