import { useState } from "react"; import { Link, useLocation, useNavigate } from "@tanstack/react-router"; import { useQuery } from "@tanstack/react-query"; import { authClient } from "@/lib/auth-client"; import { trpc } from "@/utils/trpc"; import { useSidebar } from "@/hooks/use-sidebar"; import { triggerGlobalTour } from "@/components/TourGuide"; interface NavItem { to: string; label: string; icon: string; } interface NavGroup { label?: string; items: NavItem[]; } const navGroups: NavGroup[] = [ { items: [{ to: "/dashboard", label: "Dashboard", icon: "dashboard" }], }, { label: "Generate", items: [ { to: "/generate", label: "AI Lab", icon: "auto_awesome" }, { to: "/jobs", label: "Jobs", icon: "schedule" }, ], }, { label: "Bank", items: [{ to: "/bank", label: "Buat Paket", icon: "database" }], }, { label: "Latihan", items: [ { to: "/packages", label: "Paket Soal", icon: "folder" }, { to: "/history", label: "Riwayat", icon: "history" }, ], }, { label: "Track", items: [ { to: "/analytics", label: "Analytics", icon: "analytics" }, { to: "/leaderboard", label: "Klasemen", icon: "leaderboard" }, ], }, ]; const bottomItems: NavItem[] = [ { to: "/me", label: "Profil", icon: "person" }, { to: "/settings", label: "Settings", icon: "settings" }, ]; const mobileNavItems: NavItem[] = [ { to: "/dashboard", label: "Dashboard", icon: "dashboard" }, { to: "/generate", label: "AI Lab", icon: "auto_awesome" }, { to: "/jobs", label: "Jobs", icon: "schedule" }, { to: "/bank", label: "Buat", icon: "database" }, { to: "/packages", label: "Latihan", icon: "folder" }, ]; function NavIcon({ name }: { name: string }) { return {name}; } function NavLink({ item, isActive, collapsed }: { item: NavItem; isActive: boolean; collapsed: boolean }) { const tourAttr = item.to !== "/dashboard" ? { "data-tour": `nav-${item.to.replace("/", "")}` } : {}; return ( {!collapsed && {item.label}} ); } export function Sidebar() { const location = useLocation(); const navigate = useNavigate(); const { collapsed, toggle } = useSidebar(); const { data: session } = authClient.useSession(); const isLoggedIn = !!session; const { data: adminData } = useQuery( trpc.admin.isAdmin.queryOptions(undefined, { enabled: isLoggedIn }), ); const isAdmin = !!adminData?.isAdmin; async function handleSignOut() { await authClient.signOut(); navigate({ to: "/" }); } return ( <> {/* Desktop Sidebar */} {/* Floating toggle button (right edge of sidebar) */} {/* Mobile bottom nav */} ); }