import { useCallback, type ComponentType } from "react";
import {
ArchiveIcon,
ArrowLeftIcon,
BotIcon,
CloudIcon,
GitBranchIcon,
KeyboardIcon,
Link2Icon,
Settings2Icon,
} from "lucide-react";
import { useCanGoBack, useNavigate } from "@tanstack/react-router";
import {
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarSeparator,
useSidebar,
} from "../ui/sidebar";
import { Badge } from "../ui/badge";
import { hasCloudPublicConfig } from "../../cloud/publicConfig";
export type SettingsSectionPath =
| "/settings/general"
| "/settings/keybindings"
| "/settings/providers"
| "/settings/source-control"
| "/settings/cloud"
| "/settings/connections"
| "/settings/archived";
export const SETTINGS_NAV_ITEMS: ReadonlyArray<{
label: string;
to: SettingsSectionPath;
icon: ComponentType<{ className?: string }>;
badgeLabel?: string;
}> = [
{ label: "General", to: "/settings/general", icon: Settings2Icon },
{ label: "Keybindings", to: "/settings/keybindings", icon: KeyboardIcon },
{ label: "Providers", to: "/settings/providers", icon: BotIcon },
{ label: "Source Control", to: "/settings/source-control", icon: GitBranchIcon },
{ label: "T3 Cloud", to: "/settings/cloud", icon: CloudIcon, badgeLabel: "Private Beta" },
{ label: "Connections", to: "/settings/connections", icon: Link2Icon },
{ label: "Archive", to: "/settings/archived", icon: ArchiveIcon },
];
export function SettingsSidebarNav({ pathname }: { pathname: string }) {
const navigate = useNavigate();
const canGoBack = useCanGoBack();
const { isMobile, setOpenMobile } = useSidebar();
const handleSectionClick = useCallback(
(to: SettingsSectionPath) => {
if (isMobile) {
setOpenMobile(false);
}
void navigate({ to, replace: true });
},
[isMobile, navigate, setOpenMobile],
);
const handleBackClick = useCallback(() => {
if (isMobile) {
setOpenMobile(false);
}
if (canGoBack) {
window.history.back();
return;
}
void navigate({ to: "/" });
}, [canGoBack, isMobile, navigate, setOpenMobile]);
return (
<>
{SETTINGS_NAV_ITEMS.filter(
(item) => item.to !== "/settings/cloud" || hasCloudPublicConfig(),
).map((item) => {
const Icon = item.icon;
const isActive = pathname === item.to;
return (
handleSectionClick(item.to)}
>
{item.label}
{item.badgeLabel ? (
{item.badgeLabel}
) : null}
);
})}
Back
>
);
}