import React from 'react' import { adminApi } from '../api/client' import DevNotificationsPanel from '../components/Admin/DevNotificationsPanel' import DefaultUserSettingsTab from '../components/Admin/DefaultUserSettingsTab' import { useTranslation } from '../i18n' import PageShell from '../components/Layout/PageShell' import CategoryManager from '../components/Admin/CategoryManager' import BackupPanel from '../components/Admin/BackupPanel' import GitHubPanel from '../components/Admin/GitHubPanel' import AddonManager from '../components/Admin/AddonManager' import PackingTemplateManager from '../components/Admin/PackingTemplateManager' import AuditLogPanel from '../components/Admin/AuditLogPanel' import AdminMcpTokensPanel from '../components/Admin/AdminMcpTokensPanel' import { Users, Map, Briefcase, Shield, FileText, SlidersHorizontal, UserCog, Puzzle, Settings as SettingsIcon, Bell, Database, ScrollText, KeyRound, GitBranch, Bug } from 'lucide-react' import PageSidebar, { type PageSidebarTab } from '../components/Layout/PageSidebar' import { useAdmin } from './admin/useAdmin' import AdminUpdateBanner from './admin/AdminUpdateBanner' import AdminStatCard from './admin/AdminStatCard' import AdminUsersTab from './admin/AdminUsersTab' import AdminSettingsTab from './admin/AdminSettingsTab' import AdminNotificationsTab from './admin/AdminNotificationsTab' import AdminUserModals from './admin/AdminUserModals' export default function AdminPage(): React.ReactElement { const { t, locale } = useTranslation() // Page = wiring container: all admin data slices + handlers live in the hook, // each tab/section renders from a dedicated sub-component. const admin = useAdmin() const { demoMode, mcpEnabled, devMode, toast, activeTab, setActiveTab, stats, bagTrackingEnabled, setBagTrackingEnabled, collabFeatures, setCollabFeatures, serverTimezone, updateInfo, setShowUpdateModal, } = admin const TABS: PageSidebarTab[] = [ { id: 'users', label: t('admin.tabs.users'), icon: Users }, { id: 'config', label: t('admin.tabs.config'), icon: SlidersHorizontal }, { id: 'defaults', label: t('admin.tabs.defaults'), icon: UserCog }, { id: 'addons', label: t('admin.tabs.addons'), icon: Puzzle }, { id: 'settings', label: t('admin.tabs.settings'), icon: SettingsIcon }, { id: 'notifications', label: t('admin.tabs.notifications'), icon: Bell }, { id: 'backup', label: t('admin.tabs.backup'), icon: Database }, { id: 'audit', label: t('admin.tabs.audit'), icon: ScrollText }, ...(mcpEnabled ? [{ id: 'mcp-tokens', label: t('admin.tabs.mcpTokens'), icon: KeyRound }] : []), { id: 'github', label: t('admin.tabs.github'), icon: GitBranch }, ...(devMode ? [{ id: 'dev-notifications', label: 'Dev: Notifications', icon: Bug }] : []), ] return (
{/* Header */}

{t('admin.title')}

{t('admin.subtitle')}

{/* Update Banner */} {updateInfo && ( setShowUpdateModal(true)} /> )} {/* Demo Baseline Button */} {demoMode && (

Demo Baseline

Save current state as the hourly reset point. All admin trips and settings will be preserved.

)} {/* Stats */} {stats && (
{[ { label: t('admin.stats.users'), value: stats.totalUsers, icon: Users }, { label: t('admin.stats.trips'), value: stats.totalTrips, icon: Briefcase }, { label: t('admin.stats.places'), value: stats.totalPlaces, icon: Map }, { label: t('admin.stats.files'), value: stats.totalFiles || 0, icon: FileText }, ].map(({ label, value, icon: Icon }) => ( ))}
)} {/* Sidebar layout — nav on the left, active panel on the right */} {/* Tab content */} {activeTab === 'users' && ( )} {activeTab === 'config' && (
)} {activeTab === 'addons' && (
{ const next = !bagTrackingEnabled setBagTrackingEnabled(next) try { await adminApi.updateBagTracking(next) } catch { setBagTrackingEnabled(!next) } }} collabFeatures={collabFeatures} onToggleCollabFeature={async (key: string) => { const next = { ...collabFeatures, [key]: !collabFeatures[key] } setCollabFeatures(next) try { await adminApi.updateCollabFeatures({ [key]: next[key] }) } catch { setCollabFeatures(collabFeatures) } }} />
)} {activeTab === 'settings' && ( )} {activeTab === 'notifications' && ( )} {activeTab === 'backup' && } {activeTab === 'audit' && } {activeTab === 'mcp-tokens' && } {activeTab === 'github' && } {activeTab === 'defaults' && } {activeTab === 'dev-notifications' && }
) }