import React, { useState } from 'react'; import { Navbar, Stack, UnstyledButton, Text, ThemeIcon, createStyles, Collapse, rem, Divider, useMantineTheme, } from '@mantine/core'; import { IconHome, IconUsers, IconChevronDown, IconFolder, IconSettings, IconUserCircle, } from '@tabler/icons-react'; import { Inertia } from '@inertiajs/inertia'; const useStyles = createStyles((theme) => ({ link: { display: 'flex', alignItems: 'center', width: '100%', padding: `${theme.spacing.sm}px ${theme.spacing.md}px`, borderRadius: theme.radius.sm, color: theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.black, fontWeight: 500, transition: 'all 0.2s ease', '&:hover': { backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[0], cursor: 'pointer', }, }, active: { backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[5] : theme.colors.gray[2], fontWeight: 700, }, nested: { paddingLeft: rem(32), }, toggleIcon: { marginLeft: 'auto', transition: 'transform 0.2s ease', }, sectionTitle: { color: theme.colorScheme === 'dark' ? theme.colors.dark[2] : theme.colors.gray[7], fontSize: theme.fontSizes.xs, fontWeight: 700, textTransform: 'uppercase', padding: `${theme.spacing.xs}px ${theme.spacing.md}px`, }, })); type SidebarItem = { label: string; href?: string; icon?: React.ReactNode; children?: SidebarItem[]; section?: string; }; const items: SidebarItem[] = [ { label: 'Dashboard', href: route("dashboard"), icon: , section: 'Main' }, { label: 'Clients', icon: , section: 'Main', href: route("google-ads.accounts.index"), }, { label: 'Users', icon: , section: 'Management', href: route("management.users.index"), }, { label: 'Roles', icon: , section: 'Management', href: route("management.roles.index"), }, // { label: 'Settings', href: '/settings', icon: , section: 'Management' }, ]; export default function Sidebar() { const theme = useMantineTheme(); const { classes, cx } = useStyles(); const location = window.location.pathname; const [opened, setOpened] = useState>({}); const toggle = (label: string) => { setOpened((prev) => ({ ...prev, [label]: !prev[label] })); }; const renderItem = (item: SidebarItem, depth = 0) => { const hasChildren = !!item.children?.length; const isActive = item.href === location || (hasChildren && item.children?.some((c) => c.href === location)); return ( { e.preventDefault(); if (hasChildren) toggle(item.label); else if (item.href) Inertia.visit(item.href); }} > {item.icon && {item.icon}} {item.label} {hasChildren && ( )} {hasChildren && ( {item.children!.map((child) => renderItem(child, depth + 1))} )} ); }; const sections = Array.from(new Set(items.map((i) => i.section).filter(Boolean))); return ( {sections.map((section) => ( {section} {items .filter((item) => item.section === section) .map((item) => renderItem(item))} ))} ); }