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
} 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: "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/transactions/today" },
{
title: "Pembayaran Tertunda",
href: "/pengelola/transactions/pending",
badge: "urgent"
},
{
title: "Verifikasi Pembayaran",
href: "/pengelola/transactions/verification"
},
{ title: "Riwayat Transaksi", href: "/pengelola/transactions/history" },
{ title: "Rekap Harian", href: "/pengelola/transactions/daily-recap" }
]
}
];
const fieldMenuItems: MenuItem[] = [
{
title: "Area Coverage",
icon: ,
children: [
{ title: "Peta Operasional", href: "/pengelola/coverage/map" },
{ title: "Rute Pengumpulan", href: "/pengelola/coverage/routes" },
{
title: "Titik Pengumpulan",
href: "/pengelola/coverage/collection-points"
},
{
title: "Area Prioritas",
href: "/pengelola/coverage/priority-areas",
badge: "new"
}
]
},
{
title: "Penjadwalan",
icon: ,
children: [
{ title: "Jadwal Mingguan", href: "/pengelola/schedule/weekly" },
{ title: "Pengepul On-duty", href: "/pengelola/schedule/on-duty" },
{ title: "Shift Management", href: "/pengelola/schedule/shifts" },
{
title: "Emergency Pickup",
href: "/pengelola/schedule/emergency",
badge: "urgent"
}
]
},
{
title: "Komunikasi",
icon: ,
children: [
{ title: "Chat Pengepul", href: "/pengelola/dashboard/chat" },
{
title: "Broadcast Message",
href: "/pengelola/dashboard/broadcast"
},
{
title: "Notifikasi Operasional",
href: "/pengelola/dashboard/notifications"
},
{
title: "Support Ticket",
href: "/pengelola/dashboard/support",
badge: "urgent"
}
]
},
{
title: "Task Management",
icon: ,
children: [
{ title: "Task Harian", href: "/pengelola/tasks/daily", badge: "urgent" },
{ title: "Checklist Operasi", href: "/pengelola/tasks/checklist" },
{ title: "Follow-up Required", href: "/pengelola/tasks/followup" },
{ title: "Completed Tasks", href: "/pengelola/tasks/completed" }
]
}
];
const reportingMenuItems: MenuItem[] = [
{
title: "Laporan Operasional",
icon: ,
children: [
{ title: "Laporan Harian", href: "/pengelola/reports/daily" },
{ title: "Laporan Mingguan", href: "/pengelola/reports/weekly" },
{ title: "Performa Tim", href: "/pengelola/reports/team-performance" },
{ title: "Analisis Trend", href: "/pengelola/reports/trends" }
]
},
{
title: "Monitoring Kinerja",
icon: ,
children: [
{ title: "KPI Dashboard", href: "/pengelola/kpi/dashboard" },
{ title: "Target Achievement", href: "/pengelola/kpi/targets" },
{ title: "Efficiency Metrics", href: "/pengelola/kpi/efficiency" },
{ title: "Quality Metrics", href: "/pengelola/kpi/quality" }
]
},
{
title: "Alerts & Issues",
icon: ,
children: [
{
title: "Alert Aktif",
href: "/pengelola/alerts/active",
badge: "urgent"
},
{ title: "Issue Tracking", href: "/pengelola/alerts/issues" },
{ title: "Maintenance Schedule", href: "/pengelola/alerts/maintenance" },
{ title: "Escalation Log", href: "/pengelola/alerts/escalation" }
]
},
{
title: "Pengaturan",
icon: ,
children: [
{ title: "Profil Pengelola", href: "/pengelola/settings/profile" },
{
title: "Notifikasi Setting",
href: "/pengelola/settings/notifications"
},
{ title: "Area Tanggung Jawab", href: "/pengelola/settings/area" },
{ title: "Tim & Koordinator", href: "/pengelola/settings/team" }
]
}
];
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 (
);
}