'use client' import { ReactNode, useState, useEffect } from 'react' import Link from 'next/link' import Image from 'next/image' import { usePathname, useRouter } from 'next/navigation' import { useStore } from '@/lib/store' import { KeyboardShortcutsProvider, useAdminShortcuts, ShortcutHint } from '@/hooks/useKeyboardShortcuts' import { Activity, Users, Bell, Mail, Globe, Gavel, BookOpen, Database, History, ChevronLeft, ChevronRight, LogOut, Shield, LayoutDashboard, Menu, X, Command, Settings, } from 'lucide-react' import clsx from 'clsx' // ============================================================================ // ADMIN LAYOUT // ============================================================================ interface AdminLayoutProps { children: ReactNode title?: string subtitle?: string actions?: ReactNode activeTab?: string onTabChange?: (tab: string) => void } export function AdminLayout({ children, title = 'Admin Panel', subtitle, actions, activeTab, onTabChange, }: AdminLayoutProps) { const router = useRouter() const { user, isAuthenticated, isLoading, checkAuth, logout } = useStore() const [sidebarCollapsed, setSidebarCollapsed] = useState(false) const [mobileOpen, setMobileOpen] = useState(false) useEffect(() => { checkAuth() }, [checkAuth]) useEffect(() => { if (!isLoading && !isAuthenticated) { router.push('/login') } }, [isLoading, isAuthenticated, router]) useEffect(() => { const saved = localStorage.getItem('admin-sidebar-collapsed') if (saved) setSidebarCollapsed(saved === 'true') }, []) const toggleCollapsed = () => { const newState = !sidebarCollapsed setSidebarCollapsed(newState) localStorage.setItem('admin-sidebar-collapsed', String(newState)) } if (isLoading) { return (
) } if (!isAuthenticated || !user?.is_admin) { return (

Access Denied

Admin privileges required

) } return (
{/* Background Effects */}
{/* Admin Sidebar */} setMobileOpen(false)} user={user} onLogout={logout} activeTab={activeTab} onTabChange={onTabChange} /> {/* Mobile Menu Button */} {/* Main Content */}
{/* Top Bar */}

{title}

{subtitle &&

{subtitle}

}
{actions}
{/* Page Content */}
{children}
) } // ============================================================================ // ADMIN SIDEBAR // ============================================================================ interface AdminSidebarProps { collapsed: boolean onCollapse: () => void mobileOpen: boolean onMobileClose: () => void user: any onLogout: () => void activeTab?: string onTabChange?: (tab: string) => void } function AdminSidebar({ collapsed, onCollapse, mobileOpen, onMobileClose, user, onLogout, activeTab, onTabChange, }: AdminSidebarProps) { const pathname = usePathname() const navItems = [ { id: 'overview', label: 'Overview', icon: Activity, shortcut: 'O' }, { id: 'users', label: 'Users', icon: Users, shortcut: 'U' }, { id: 'alerts', label: 'Price Alerts', icon: Bell }, { id: 'newsletter', label: 'Newsletter', icon: Mail }, { id: 'tld', label: 'TLD Data', icon: Globe }, { id: 'auctions', label: 'Auctions', icon: Gavel }, { id: 'blog', label: 'Blog', icon: BookOpen, shortcut: 'B' }, { id: 'system', label: 'System', icon: Database, shortcut: 'Y' }, { id: 'activity', label: 'Activity Log', icon: History }, ] const SidebarContent = () => ( <> {/* Logo */}
{!collapsed && (
Admin Control Panel
)}
{/* Navigation */} {/* Bottom Section */}
{/* Back to User Dashboard */} {!collapsed && ( <> User Dashboard )} {/* User Info */} {!collapsed && (

{user?.name || user?.email?.split('@')[0]}

Administrator

)} {/* Logout */}
{/* Collapse Toggle */} ) return ( <> {/* Mobile Overlay */} {mobileOpen && (
)} {/* Mobile Sidebar */} {/* Desktop Sidebar */} ) } // ============================================================================ // SHORTCUTS WRAPPER // ============================================================================ function AdminShortcutsWrapper() { useAdminShortcuts() return null }