'use client'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useState, useEffect } from 'react'; import { Bike, Settings, Wallet, Store, Zap, Battery, Menu, X, Users, FileText, BarChart3, CreditCard, MapPin, Shield, Truck, ChevronDown, LogOut, Calculator, Wrench } from 'lucide-react'; import { getUserName, getUserRole, logout } from '@/lib/auth'; const ROLE_LABELS: Record = { super_admin: 'Super Admin', admin_manager: 'Admin Manager', staff: 'Front Desk', accountant: 'Accountant', investor: 'Investor', biker: 'Biker', 'swap-station': 'Swap Station', merchant: 'Merchant', }; const adminNavItems = [ { label: 'Dashboard', href: '/admin', icon: BarChart3 }, { label: 'KYC Requests', href: '/admin/kyc', icon: Shield }, { label: 'Rentals', href: '/admin/rentals', icon: FileText }, { label: 'Bikers', href: '/admin/bikers', icon: Users }, { label: 'Investors', href: '/admin/investors', icon: Wallet }, { label: 'Fleet Management', href: '/admin/fleet', icon: Bike }, { label: 'Merchants (P2)', href: '/admin/merchants', icon: Store }, { label: 'Swap Stations (P3)', href: '/admin/swap-stations', icon: Zap }, { label: 'Damage & Maintenance', href: '/admin/maintenance', icon: Wrench }, { label: 'Accounting', href: '/admin/accounting', icon: Calculator }, { label: 'Hubs', href: '/admin/hub', icon: MapPin }, { label: 'Reports', href: '/admin/reports', icon: BarChart3 }, { label: 'Users Management', href: '/admin/users', icon: Users }, { label: 'Roles & Permissions', href: '/admin/roles', icon: Shield }, { label: 'Settings', href: '/admin/settings', icon: Settings }, ]; const bikerNavItems = [ { label: 'Biker Dashboard', href: '/', icon: Bike }, { label: 'Rent Bike', href: '/rent', icon: Zap }, { label: 'Browse EVs', href: '/bikes', icon: Battery }, ]; const investorNavItems = [ { label: 'Dashboard', href: '/investor', icon: Wallet }, ]; const shopNavItems = [ { label: 'Dashboard', href: '/shop', icon: Store }, { label: 'Deliveries', href: '/shop/deliveries', icon: Truck }, { label: 'Fleet', href: '/shop/fleet', icon: Bike }, ]; export default function Sidebar() { const pathname = usePathname(); const [mobileOpen, setMobileOpen] = useState(false); const [expandedMenu, setExpandedMenu] = useState(null); const [userName, setUserName] = useState('User'); const [userRole, setUserRole] = useState('admin'); useEffect(() => { setUserName(getUserName() || 'User'); setUserRole(getUserRole() || 'staff'); }, []); const isAdmin = pathname.startsWith('/admin'); const isInvestor = pathname.startsWith('/investor'); const isShop = pathname.startsWith('/shop'); const roleLabel = ROLE_LABELS[userRole] || userRole; const navItems = isAdmin ? adminNavItems : isInvestor ? investorNavItems : isShop ? shopNavItems : bikerNavItems; const bottomNavItems = isAdmin ? [ { label: 'Home', href: '/admin', icon: BarChart3 }, { label: 'Fleet', href: '/admin/fleet', icon: Bike }, { label: 'Users', href: '/admin/users', icon: Users }, ] : isInvestor ? [ { label: 'Home', href: '/investor', icon: Wallet }, { label: 'Portfolio', href: '/investor/portfolio', icon: BarChart3 }, { label: 'Withdraw', href: '/investor/withdraw', icon: CreditCard }, ] : isShop ? [ { label: 'Home', href: '/shop', icon: Store }, { label: 'Deliveries', href: '/shop/deliveries', icon: Truck }, { label: 'Fleet', href: '/shop/fleet', icon: Bike }, ] : [ { label: 'Home', href: '/', icon: Bike }, { label: 'Rent', href: '/rent', icon: Zap }, { label: 'EVs', href: '/bikes', icon: Battery }, ]; return ( <> {/* Bottom Navigation for Mobile */} {mobileOpen && (
setMobileOpen(false)} /> )} ); }