import React, { useMemo } from 'react'; import { NavLink, Outlet } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { usePluginStore } from '@/store/pluginStore'; import { useUIStore } from '@/store/uiStore'; import { Settings, Mail, Bell, Sparkles, Bot, Shield, Users, UsersRound, Package } from 'lucide-react'; const ICON_MAP: Record> = { Settings, Mail, Bell, Sparkles, Bot, Shield, Users, UsersRound, }; const FALLBACK_ICON = Package; export function SettingsPage() { const { t } = useTranslation(); const manifests = usePluginStore(s => s.manifests); const sidebarOpen = useUIStore((state) => state.sidebarOpen); const pluginSettingsPages = useMemo( () => (manifests || []) .flatMap((m) => (Array.isArray(m.settings_pages) ? m.settings_pages : [])) .filter((p): p is NonNullable => !!p && !!p.path) .sort((a, b) => a.order - b.order), [manifests] ); const hardcodedNavItems = [ { to: '/settings/stammdaten', label: 'Stammdaten', icon: '\ud83c\udfe2' }, { to: '/settings/user-management', label: 'Nutzerverwaltung', icon: '\ud83d\udc65' }, { to: '/settings/system', label: 'System', icon: '\u2699\ufe0f' }, { to: '/settings/mail', label: t('mail.settings'), icon: '\ud83d\udce7' }, { to: '/settings/ai-settings', label: 'KI Einstellungen', icon: '\ud83e\udde0' }, { to: '/settings/notifications', label: t('settings.notifications'), icon: '\ud83d\udd14' }, { to: '/settings/custom-fields', label: 'Custom Fields', icon: '\ud83d\udccb' }, { to: '/settings/webhooks', label: 'Webhooks', icon: '\ud83d\udd14' }, { to: '/settings/workspaces', label: 'Workspaces', icon: '\ud83d\udd58\ufe0f' }, { to: '/settings/backup', label: 'Backup & Restore', icon: '\ud83d\udcbe' }, ]; const existingPaths = new Set(hardcodedNavItems.map(item => item.to)); // Filter out plugin nav items that are duplicates of hardcoded ones const duplicateLabels = new Set(['Roles', 'Users', 'Groups', 'AI Settings', 'Automation', 'Proactive AI']); const pluginNavItems = pluginSettingsPages .filter(p => !existingPaths.has(`/settings/${p.path}`)) .filter(p => !duplicateLabels.has(p.label)) .map(p => ({ to: `/settings/${p.path}`, label: t(p.label_key, p.label), icon: (() => { const Icon = ICON_MAP[p.icon] ?? FALLBACK_ICON; return React.createElement(Icon, { className: 'w-4 h-4' }); })(), })); const navItems = [...hardcodedNavItems, ...pluginNavItems]; return (
); }