'use client' import { useEffect, useState } from 'react' import Link from 'next/link' import { usePathname } from 'next/navigation' import { cn } from '@/lib/utils' import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { Store, ClipboardList, ShoppingBag, UserCircle, Sparkles, X, ArrowUpRight, Info, BarChart2, Wallet, Settings, } from 'lucide-react' const menuItems = [ { name: 'Open Order', href: '/', icon: Store, desc: 'Daftar PO live hari ini' }, { name: 'Jasa Order Saya', href: '/my-orders', icon: ClipboardList, desc: 'Kelola PO buatan Anda', }, { name: 'Pesanan Saya', href: '/my-purchases', icon: ShoppingBag, desc: 'Riwayat titipan Anda' }, { name: 'Buku Saldo', href: '/balances', icon: Wallet, desc: 'Pantau riwayat saldo' }, { name: 'Laporan', href: '/reports', icon: BarChart2, desc: 'Ringkasan transaksi' }, ] export function Sidebar({ isOpen, onClose }: { isOpen?: boolean; onClose?: () => void }) { const pathname = usePathname() const [userName, setUserName] = useState('Pengguna') const [userNameAccount, setUserNameAccount] = useState('Pengguna') const [userPhoto, setUserPhoto] = useState(null) const [userRole, setUserRole] = useState(null) const [userId, setUserId] = useState(null) const [isLogoutOpen, setIsLogoutOpen] = useState(false) useEffect(() => { import('@/app/actions').then(({ getSessionUser }) => { getSessionUser().then((u) => { if (u) { setUserId(u.id) setUserName(u.name) setUserNameAccount(u.username) setUserRole(u.role) if (u.photo) setUserPhoto(u.photo) } }) }) }, [pathname]) const handleLogout = async () => { const { logoutUser } = await import('@/app/actions') await logoutUser() window.location.href = '/login' } // Dynamic Menu Items based on role const finalMenuItems = [...menuItems] if (userRole === 'superadmin') { finalMenuItems.push({ name: 'Pengaturan', href: '/settings/users', icon: Settings, desc: 'Konfigurasi aplikasi', }) } return ( <> {/* Mobile Backdrop */} {isOpen && (
)} ) }