import { OverviewIcon, AboutIcon, RestartIcon, CapabilitiesIcon, AppearanceIcon, SystemIcon, AdvancedIcon, ModelsIcon, } from "@/components/icons/product-icons"; import { useContext, useRef, useState } from "react"; import { HostNavigationContext, HostSwitcher } from "@/components/remote/HostSwitcher"; import { Check, ChevronDown, ChevronLeft, LogOut, Loader2, type LucideIcon } from "lucide-react"; import { useTranslation } from "react-i18next"; import { SIDEBAR_SELECTION_ITEM_CLASS, SidebarSelectionHighlight, } from "@/components/SidebarSelectionHighlight"; import { isCapabilitySection, type SettingsSectionKey } from "@/components/settings/contracts"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { useMediaQuery } from "@/hooks/useMediaQuery"; import { cn } from "@/lib/utils"; const SETTINGS_NAV_ITEMS: Array<{ key: SettingsSectionKey; icon: LucideIcon; fallback: string }> = [ { key: "overview", icon: OverviewIcon, fallback: "Overview" }, { key: "appearance", icon: AppearanceIcon, fallback: "Appearance" }, { key: "models", icon: ModelsIcon, fallback: "Models" }, { key: "capabilities", icon: CapabilitiesIcon, fallback: "Capabilities" }, { key: "runtime", icon: SystemIcon, fallback: "System" }, { key: "advanced", icon: AdvancedIcon, fallback: "Advanced" }, { key: "about", icon: AboutIcon, fallback: "About" }, ]; export function standaloneSectionTitle(section: SettingsSectionKey): string { if (section === "apps") return "Apps"; if (section === "automations") return "Automations"; if (section === "skills") return "Skills"; if (section === "channels") return "Channels"; return SETTINGS_NAV_ITEMS.find((item) => item.key === section)?.fallback ?? "Settings"; } interface SettingsSidebarProps { activeSection: SettingsSectionKey; onSelectSection: (section: SettingsSectionKey) => void; onBackToChat: () => void; onLogout?: () => void; hostChromeInset?: boolean; onRestart?: () => void; isRestarting?: boolean; restartPending?: boolean; isNativeHost?: boolean; } export function SettingsSidebar(props: SettingsSidebarProps) { const { activeSection, onSelectSection, onBackToChat, onLogout, hostChromeInset, onRestart, isRestarting, restartPending, isNativeHost, } = props; const { t } = useTranslation(); const hostNavigation = useContext(HostNavigationContext); const mobile = useMediaQuery("(max-width: 1023px)"); const restartLabel = isRestarting ? t(isNativeHost ? "app.system.restartingEngine" : "app.system.restarting") : t("app.system.restartAction"); const navSection = isCapabilitySection(activeSection) ? "capabilities" : activeSection; const activeNavItemRef = useRef(null); const activeItem = SETTINGS_NAV_ITEMS.find((item) => item.key === navSection) ?? SETTINGS_NAV_ITEMS[0]; const activeLabel = t(`settings.nav.${activeItem.key}`, { defaultValue: activeItem.fallback, }); if (mobile) { return ; } return ( ); } // Mount only on narrow screens so an open menu cannot survive a switch to desktop. function MobileSettingsNavigation({ navSection, activeLabel, restartLabel, onSelectSection, onBackToChat, hostChromeInset, onRestart, isRestarting, restartPending, }: SettingsSidebarProps & { navSection: SettingsSectionKey; activeLabel: string; restartLabel: string; }) { const { t } = useTranslation(); const hostNavigation = useContext(HostNavigationContext); const [open, setOpen] = useState(false); const restart = () => { setOpen(false); onRestart?.(); }; const restartTone = restartPending && !isRestarting ? "text-orange-600 hover:text-orange-700 dark:text-orange-400 dark:hover:text-orange-300" : "text-muted-foreground hover:text-foreground"; const restartIcon = isRestarting ? : ; const restartAction = onRestart ? ( ) : null; return ( ); }