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, Truck, Calendar, ClipboardList, Target, Timer, AlertCircle, CheckCircle, Route, Phone, Search } 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 operationalMenuItems: MenuItem[] = [ { title: "Dashboard", icon: , children: [ { title: "Overview Harian", href: "/pengelola/dashboard" }, { title: "Monitoring Real-time", href: "/pengelola/dashboard/monitoring", badge: "new" }, { title: "Target vs Pencapaian", href: "/pengelola/dashboard/targets" }, { title: "Jadwal Hari Ini", href: "/pengelola/dashboard/schedule" } ] }, { title: "Operasional Sampah", icon: , children: [ { title: "Pengumpulan Harian", href: "/pengelola/dashboard/collection", badge: "urgent" }, { title: "Sortir & Klasifikasi", href: "/pengelola/dashboard/sorting" }, { title: "Stok Sampah", href: "/pengelola/dashboard/inventory" }, { title: "Kualitas Check", href: "/pengelola/dashboard/quality" }, { title: "Input Data Berat", href: "/pengelola/dashboard/weight-input", badge: "new" } ] }, { title: "Explore", icon: , href: "/pengelola/dashboard/explorewaste" }, { title: "Manajemen Pengepul", icon: , children: [ { title: "Daftar Pengepul Aktif", href: "/pengelola/collectors/active" }, { title: "Jadwal Pickup", href: "/pengelola/collectors/schedule" }, { title: "Performa Pengepul", href: "/pengelola/collectors/performance" }, { title: "Pengepul Pending", href: "/pengelola/collectors/pending", badge: "urgent" }, { title: "Rating & Feedback", href: "/pengelola/collectors/feedback" } ] }, { title: "Transaksi & Pembayaran", icon: , children: [ { title: "Transaksi Hari Ini", href: "/pengelola/dashboard/transactions" } ] } ]; const fieldMenuItems: MenuItem[] = [ { title: "Komunikasi", icon: , children: [ { title: "Chat Pengepul", href: "/pengelola/dashboard/chat" }, { title: "Broadcast Message", href: "/pengelola/dashboard/broadcast" } ] } ]; const reportingMenuItems: MenuItem[] = [ { title: "Pengaturan", icon: , children: [ { title: "Profil Pengelola", href: "/pengelola/dashboard/pengaturan" } ] } ]; 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 PengelolaSidebar({ isOpen, isCollapsed, isHovered, isMobile, onClose, onMouseEnter, onMouseLeave }: SidebarProps) { const sidebarWidth = isCollapsed && !isHovered ? "w-20" : "w-72"; const showText = !isCollapsed || isHovered; return ( ); }