'use client'; import { LayoutDashboard, Users, ClipboardList, ShieldCheck, Building2, Factory, LogOut, Menu, Sparkles, X, } from 'lucide-react'; import { usePathname, useRouter } from 'next/navigation'; import { useTranslations } from 'next-intl'; import { useEffect, useState } from 'react'; import { Button } from '@/components/ui/button'; import { LanguageSwitcher } from '@/components/ui/language-switcher'; import { Link } from '@/i18n/navigation'; import { useAuthStore } from '@/lib/auth-store'; import { cn } from '@/lib/utils'; export default function AdminLayout({ children }: { children: React.ReactNode }) { const pathname = usePathname(); const router = useRouter(); const { user, isAuthenticated, isInitialized, logout } = useAuthStore(); const [sidebarOpen, setSidebarOpen] = useState(false); const t = useTranslations(); const adminNavItems = [ { href: '/admin' as const, label: t('adminNav.dashboard'), icon: LayoutDashboard }, { href: '/admin/users' as const, label: t('adminNav.users'), icon: Users }, { href: '/admin/moderation' as const, label: t('adminNav.moderation'), icon: ClipboardList }, { href: '/admin/kyc' as const, label: t('adminNav.kyc'), icon: ShieldCheck }, { href: '/admin/accounts/developers' as const, label: 'Tài khoản CĐT', icon: Building2 }, { href: '/admin/accounts/park-operators' as const, label: 'Tài khoản KCN', icon: Factory }, { href: '/admin/settings/ai' as const, label: t('adminNav.aiSettings'), icon: Sparkles }, ]; useEffect(() => { // Once the auth store finished its initial cookie→profile probe: // - no session → push to /login (don't leave a spinner forever) // - authenticated but not ADMIN → push to regular dashboard if (!isInitialized) return; if (!isAuthenticated) { router.replace(`/login?next=${encodeURIComponent(pathname)}`); return; } if (user && user.role !== 'ADMIN') { router.replace('/dashboard'); } }, [isInitialized, isAuthenticated, user, router, pathname]); if (!isInitialized || !user) { return (