import { Menu } from 'antd'; import { useLocation, useNavigate } from '@tanstack/react-router'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faChartLine, faClipboardList, faClipboardCheck, faFunnelDollar, faUsers, faAddressCard, faBoxesStacked, faFileInvoiceDollar, faTags, } from '@fortawesome/free-solid-svg-icons'; import type { ItemType } from 'antd/es/menu/interface'; import { authStore } from '../../lib/auth-store'; function getRole(): string { const token = authStore.get(); if (!token) return 'rep'; try { const payload = JSON.parse(atob(token.split('.')[1] ?? '')); return (payload.role as string) ?? 'rep'; } catch { return 'rep'; } } const REP_ITEMS: ItemType[] = [ { key: '/', icon: , label: 'Painel' }, { key: '/clientes', icon: , label: 'Clientes' }, { key: '/catalogo', icon: , label: 'Catálogo', }, { key: '/funil', icon: , label: 'Funil de Vendas', }, { key: '/pedidos', icon: , label: 'Pedidos', }, { key: '/pedidos-erp', icon: , label: 'Consulta ERP', }, { key: '/relatorios', icon: , label: 'Relatórios', }, ]; const SUPERVISOR_ITEMS: ItemType[] = [ { key: '/', icon: , label: 'Painel' }, { key: '/aprovacoes', icon: , label: 'Aprovações', }, { key: '/clientes', icon: , label: 'Clientes' }, { key: '/pedidos', icon: , label: 'Pedidos', }, { key: '/catalogo', icon: , label: 'Catálogo', }, { key: '/relatorios', icon: , label: 'Relatórios', }, ]; const GERENTE_ITEMS: ItemType[] = [ { key: '/ger', icon: , label: 'Painel' }, { key: '/ger/equipe', icon: , label: 'Equipe' }, { key: '/clientes', icon: , label: 'Clientes', }, { key: '/relatorios', icon: , label: 'Relatórios', }, { key: '/ger/politicas', icon: , label: 'Políticas Comerciais', }, ]; function getItems(role: string): ItemType[] { if (role === 'manager' || role === 'admin') return GERENTE_ITEMS; if (role === 'supervisor') return SUPERVISOR_ITEMS; return REP_ITEMS; } export function Sidebar() { const navigate = useNavigate(); const location = useLocation(); const role = getRole(); const items = getItems(role); const selectedKey = items.find((item) => { const key = (item as { key?: string }).key ?? ''; return key === '/' ? location.pathname === '/' : location.pathname.startsWith(key); })?.key as string | undefined; return ( ); }