import { useNavigate, useLocation } from 'react-router-dom'; import useAuthStore from '../store/useAuthStore'; import { getCompanySlug } from '../utils/slug'; const superAdminMenus = [ { path: '/admin/companies', label: 'Perusahaan', icon: 'store' }, { path: '/admin/tenant-settings', label: 'Pengaturan Tenant', icon: 'settings' }, { path: '/admin/topups', label: 'Verifikasi Saldo', icon: 'fact_check' }, { path: '/admin/fees', label: 'Fee Report', icon: 'payments' }, ]; const ownerMenus = [ { path: '/dashboard', label: 'Dashboard', icon: 'dashboard' }, { path: '/pos', label: 'Kasir (POS)', icon: 'point_of_sale' }, { path: '/admin/branches', label: 'Cabang', icon: 'store' }, { path: '/admin/products', label: 'Produk', icon: 'inventory_2' }, { path: '/admin/categories', label: 'Kategori', icon: 'category' }, { path: '/admin/kasir', label: 'Kasir', icon: 'group' }, { path: '/admin/orders', label: 'Riwayat Order', icon: 'receipt_long' }, { path: '/admin/members', label: 'Member', icon: 'group' }, { path: '/admin/vouchers', label: 'Katalog Voucher', icon: 'confirmation_number' }, { path: '/admin/wallet', label: 'Dompet Saldo', icon: 'account_balance_wallet' }, { path: '/owner/report', label: 'Laporan Harian', icon: 'bar_chart' }, ]; const kasirMenus = [ { path: '/pos', label: 'Kasir (POS)', icon: 'point_of_sale' }, { path: '/admin/members', label: 'Member', icon: 'group' }, { path: '/kasir/report', label: 'Laporan Harian', icon: 'bar_chart' }, ]; export default function Sidebar() { const navigate = useNavigate(); const location = useLocation(); const { user, logout } = useAuthStore(); const slug = getCompanySlug(user?.company_name); const getNavPath = (menuPath) => { if (user?.role === 'super_admin') return menuPath; return `/${slug}${menuPath}`; }; let menus = user?.role === 'super_admin' ? superAdminMenus : user?.role === 'owner' ? ownerMenus : kasirMenus; if (user?.role !== 'super_admin') { const settings = user?.company_settings || {}; if (settings.enable_member === false) { menus = menus.filter(m => m.path !== '/admin/members'); } if (settings.enable_voucher === false) { menus = menus.filter(m => m.path !== '/admin/vouchers'); } } return ( ); }