"use client"; import type { ReactNode } from 'react'; import { Navigate, NavLink, useLocation } from '@/lib/router'; import { useMemo } from 'react'; import { useAuth } from '@/contexts/AuthContext'; const navItems = [ { to: '/admin/users', label: 'مدیریت کاربران' }, { to: '/admin/events', label: 'مدیریت رویدادها' }, ] as const; export default function AdminLayout({ children }: { children: ReactNode }) { const location = useLocation(); const { user, isAuthenticated, loading } = useAuth(); const isAdmin = useMemo( () => isAuthenticated && Boolean(user?.is_staff || user?.is_superuser), [isAuthenticated, user?.is_staff, user?.is_superuser], ); if (loading) { return (
در حال بارگذاری...
); } if (!isAdmin) { return ; } return (

پنل مدیریت

{navItems.map((item) => ( [ 'rounded-full px-4 py-2 text-sm transition', (isActive || location.pathname?.startsWith(item.to)) ? 'bg-primary text-primary-foreground shadow' : 'bg-card text-muted-foreground hover:text-foreground border', ].join(' ') } > {item.label} ))}
{children}
); }