"use client" import type * as React from "react" import Image from "next/image" import { usePathname } from "next/navigation" import { AppWindow, Settings, LayoutDashboardIcon, Briefcase, Server, Network, Activity, LogOut, ChevronDown, } from "lucide-react" import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarRail, SidebarFooter, } from "@/components/ui/sidebar" import { Button } from "@/components/ui/button" import Link from "next/link" import Cookies from "js-cookie" import { useRouter } from "next/navigation" import packageJson from "@/package.json" import { cn } from "@/lib/utils" import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible" import { useTranslations } from "next-intl" interface NavItem { title: string icon?: React.ComponentType url: string isActive?: boolean items?: NavItem[] } export function AppSidebar({ ...props }: React.ComponentProps) { const t = useTranslations('Sidebar') const data: { navMain: NavItem[] } = { navMain: [ { title: t('Dashboard'), icon: LayoutDashboardIcon, url: "/dashboard", }, { title: t('My Infrastructure'), url: "#", icon: Briefcase, items: [ { title: t('Servers'), icon: Server, url: "/dashboard/servers", }, { title: t('Applications'), icon: AppWindow, url: "/dashboard/applications", }, { title: t('Uptime'), icon: Activity, url: "/dashboard/uptime", }, { title: t('Network'), icon: Network, url: "/dashboard/network", }, ], }, { title: t('Settings'), icon: Settings, url: "/dashboard/settings", }, ], } const router = useRouter() const pathname = usePathname() const logout = async () => { Cookies.remove("token") router.push("/") } // Check if a path is active (exact match or starts with path for parent items) const isActive = (path: string) => { if (path === "#") return false return pathname === path || (path !== "/dashboard" && pathname?.startsWith(path)) } // Check if any child item is active const hasActiveChild = (items?: NavItem[]) => { if (!items) return false return items.some((item) => isActive(item.url)) } return (
CoreControl Logo
CoreControl v{packageJson.version}
{t('Main Navigation')} {data.navMain.map((item) => item.items?.length ? ( {item.icon && } {item.title} {item.items.map((subItem) => ( {subItem.icon && } {subItem.title} ))} ) : ( {item.icon && } {item.title} ), )}
) }