import { Bell as AlertRegular, RefreshCw as ArrowSyncRegular, Container as BoxRegular, CalendarClock as CalendarClockRegular, Database as DatabaseRegular, HardDrive as HardDriveRegular, Paintbrush as PaintBrushRegular, Plug as PlugRegular, Users as PeopleRegular, Power as PowerRegular, Router as RouterRegular, Server as ServerRegular, Shield as ShieldRegular, Wrench as WrenchRegular, } from "@/components/icons/platform-icons"; import { AdvancedSection, AppearanceSection, BackupSection, DockerSection, GeneralSection, IntegrationsSection, NetworkSection, NotificationsSection, PowerSection, ScheduledTasksSection, SecuritySection, StorageSection, UpdatesSection, UsersSection, } from "@/modules/settings/components/panel/sections"; import type { DesktopPreferencesApi, SettingsBackend, SettingsSection, SettingsSectionDefinition, } from "@/modules/settings/components/panel/types"; export const SETTINGS_SECTIONS: SettingsSection[] = [ // System { id: "general", label: "General", icon: ServerRegular }, { id: "appearance", label: "Appearance", icon: PaintBrushRegular }, { id: "updates", label: "Updates", icon: ArrowSyncRegular }, // Infrastructure { id: "network", label: "Network", icon: RouterRegular }, { id: "storage", label: "Storage", icon: HardDriveRegular }, { id: "docker", label: "Docker", icon: BoxRegular }, // Integrations { id: "integrations", label: "Integrations", icon: PlugRegular }, // Automation { id: "scheduled-tasks", label: "Scheduled Tasks", icon: CalendarClockRegular }, { id: "backup", label: "Backup & Restore", icon: DatabaseRegular }, // Access & Safety { id: "users", label: "Users & Access", icon: PeopleRegular }, { id: "security", label: "Security", icon: ShieldRegular }, { id: "notifications", label: "Notifications", icon: AlertRegular }, // Danger zone { id: "power", label: "Power", icon: PowerRegular }, { id: "advanced", label: "Advanced", icon: WrenchRegular }, ]; type SettingsRegistryContext = { appearance: Parameters[0]["appearance"]; wallpaperOptions: Parameters[0]["wallpaperOptions"]; accentOptions: Parameters[0]["accentOptions"]; onAppearanceChange: Parameters[0]["onAppearanceChange"]; wallpaperAccentColor: Parameters[0]["wallpaperAccentColor"]; desktopPreferences: DesktopPreferencesApi; settingsBackend: SettingsBackend; onOpenDiskManager?: () => void; generalController: { draft: { hostname: string; timezone: string }; setHostname: (value: string) => void; setTimezone: (value: string) => void; saveState: SettingsSectionDefinition["save"]; save: () => Promise; }; securityController: { draft: Parameters[0]["draft"]; patchDraft: (patch: Partial[0]["draft"]>) => void; saveState: SettingsSectionDefinition["save"]; save: () => Promise; }; notificationController: { draft: Parameters[0]["draft"]; patchDraft: (patch: Partial[0]["draft"]>) => void; saveState: SettingsSectionDefinition["save"]; save: () => Promise; }; backupController: { draft: Parameters[0]["settingsDraft"]; patchDraft: (patch: Partial[0]["settingsDraft"]>) => void; saveState: SettingsSectionDefinition["save"]; save: () => Promise; }; }; function getDefaultSaveConfig( settingsBackend: SettingsBackend, sectionId: keyof SettingsBackend["capabilities"]["saveBySection"], ) { const visible = settingsBackend.capabilities.saveBySection[sectionId] ?? false; if (!visible) return undefined; return { canSave: false, title: settingsBackend.capabilities.saveDisabledReason, pending: false, label: "Save Changes", onSave: undefined, }; } export function buildSettingsSectionDefinitions( context: SettingsRegistryContext, ): SettingsSectionDefinition[] { return [ // ── System ────────────────────────────────────────────────────────── { ...SETTINGS_SECTIONS[0], // General render: () => ( o.label)} onHostnameChange={context.generalController.setHostname} onTimezoneChange={context.generalController.setTimezone} onLanguageChange={(value) => { const next = context.desktopPreferences.languageOptions.find((o) => o.label === value); if (!next) return; context.desktopPreferences.setLanguage(next.code); }} /> ), save: context.generalController.saveState ? { ...context.generalController.saveState, onSave: context.generalController.save } : getDefaultSaveConfig(context.settingsBackend, "general"), }, { ...SETTINGS_SECTIONS[1], // Appearance liveApply: true, render: () => ( ), }, { ...SETTINGS_SECTIONS[2], // Updates render: () => ( context.desktopPreferences.setAutoCheckUpdates(enabled)} /> ), save: getDefaultSaveConfig(context.settingsBackend, "updates"), }, // ── Infrastructure ─────────────────────────────────────────────────── { ...SETTINGS_SECTIONS[3], // Network render: () => , save: getDefaultSaveConfig(context.settingsBackend, "network"), }, { ...SETTINGS_SECTIONS[4], // Storage render: () => , save: getDefaultSaveConfig(context.settingsBackend, "storage"), }, { ...SETTINGS_SECTIONS[5], // Docker render: () => ( ), save: getDefaultSaveConfig(context.settingsBackend, "docker"), }, // ── Integrations ───────────────────────────────────────────────────── { ...SETTINGS_SECTIONS[6], // Integrations render: () => , }, // ── Automation ─────────────────────────────────────────────────────── { ...SETTINGS_SECTIONS[7], // Scheduled Tasks render: () => , }, { ...SETTINGS_SECTIONS[8], // Backup & Restore render: () => ( ), save: context.backupController.saveState ? { ...context.backupController.saveState, onSave: context.backupController.save } : getDefaultSaveConfig(context.settingsBackend, "backup"), }, // ── Access & Safety ────────────────────────────────────────────────── { ...SETTINGS_SECTIONS[9], // Users & Access render: () => ( ), save: getDefaultSaveConfig(context.settingsBackend, "users"), }, { ...SETTINGS_SECTIONS[10], // Security render: () => ( ), save: context.securityController.saveState ? { ...context.securityController.saveState, onSave: context.securityController.save } : getDefaultSaveConfig(context.settingsBackend, "security"), }, { ...SETTINGS_SECTIONS[11], // Notifications render: () => ( ), save: context.notificationController.saveState ? { ...context.notificationController.saveState, onSave: context.notificationController.save } : getDefaultSaveConfig(context.settingsBackend, "notifications"), }, // ── Danger zone ────────────────────────────────────────────────────── { ...SETTINGS_SECTIONS[12], // Power render: () => ( ), save: getDefaultSaveConfig(context.settingsBackend, "power"), }, { ...SETTINGS_SECTIONS[13], // Advanced render: () => , }, ]; }