"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { adminFetch } from "@/lib/csrf"; import { LayoutDashboard, Sparkles, Users, BookOpen, Star, Calendar, DollarSign, HelpCircle, Phone, FileText, Globe, Newspaper, LogOut, Menu, X, ChevronLeft, ClipboardList, DoorOpen, } from "lucide-react"; const NAV_ITEMS = [ { href: "/admin", label: "Дашборд", icon: LayoutDashboard }, { href: "/admin/meta", label: "SEO / Мета", icon: Globe }, { href: "/admin/hero", label: "Главный экран", icon: Sparkles }, { href: "/admin/about", label: "О студии", icon: FileText }, { href: "/admin/team", label: "Команда", icon: Users }, { href: "/admin/classes", label: "Направления", icon: BookOpen }, { href: "/admin/master-classes", label: "Мастер-классы", icon: Star }, { href: "/admin/open-day", label: "День открытых дверей", icon: DoorOpen }, { href: "/admin/schedule", label: "Расписание", icon: Calendar }, { href: "/admin/bookings", label: "Записи", icon: ClipboardList }, { href: "/admin/pricing", label: "Цены", icon: DollarSign }, { href: "/admin/faq", label: "FAQ", icon: HelpCircle }, { href: "/admin/news", label: "Новости", icon: Newspaper }, { href: "/admin/contact", label: "Контакты", icon: Phone }, ]; export default function AdminLayout({ children, }: { children: React.ReactNode; }) { const pathname = usePathname(); const router = useRouter(); const [sidebarOpen, setSidebarOpen] = useState(false); const [unreadTotal, setUnreadTotal] = useState(0); const isLoginPage = pathname === "/admin/login"; // Fetch unread counts — poll every 10s useEffect(() => { if (isLoginPage) return; function fetchCounts() { adminFetch("/api/admin/unread-counts") .then((r) => r.json()) .then((data: { total: number }) => setUnreadTotal(data.total)) .catch(() => {}); } fetchCounts(); const interval = setInterval(fetchCounts, 10000); return () => clearInterval(interval); }, [isLoginPage]); // Don't render admin shell on login page if (isLoginPage) { return <>{children}; } async function handleLogout() { await fetch("/api/logout", { method: "POST" }); router.push("/admin/login"); } function isActive(href: string) { if (href === "/admin") return pathname === "/admin"; return pathname.startsWith(href); } return (
{/* Mobile overlay */} {sidebarOpen && (
setSidebarOpen(false)} /> )} {/* Sidebar */} {/* Main content */}
{/* Top bar (mobile) */}
BLACK HEART
{children}
); }