"use client"; import { Home } from "lucide-react"; import { usePathname, useRouter } from "next/navigation"; import { LighthouseIcon } from "@/components/icons/Icons"; import { Badge } from "@/components/shadcn/badge/badge"; import { NavigationButton } from "@/components/shadcn/navigation-button"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/shadcn/tooltip"; import { isLighthouseChatRoute, LIGHTHOUSE_ROUTE, } from "@/lib/lighthouse-routes"; import { useCloudUpgradeStore } from "@/store"; import { CLOUD_UPGRADE_FEATURE } from "@/types/cloud-upgrade"; import { useAppSidebarMode } from "./app-sidebar-mode-store"; import { APP_SIDEBAR_MODE, type AppSidebarMode, type AppSidebarSelectionHandler, } from "./types"; interface AppSidebarModeToggleProps { chatEnabled: boolean; onSelect?: AppSidebarSelectionHandler; } const MODES = [ { value: APP_SIDEBAR_MODE.BROWSE, label: "Home", icon: Home, }, { value: APP_SIDEBAR_MODE.CHAT, label: "Chat", icon: LighthouseIcon, }, ] as const; export function AppSidebarModeToggle({ chatEnabled, onSelect, }: AppSidebarModeToggleProps) { const router = useRouter(); const pathname = usePathname(); const mode = useAppSidebarMode((state) => state.mode); const setMode = useAppSidebarMode((state) => state.setMode); const openCloudUpgrade = useCloudUpgradeStore( (state) => state.openCloudUpgrade, ); const selectMode = (nextMode: AppSidebarMode) => { const isChatUpsell = nextMode === APP_SIDEBAR_MODE.CHAT && !chatEnabled; if (isChatUpsell) { openCloudUpgrade( CLOUD_UPGRADE_FEATURE.LIGHTHOUSE_AI, onSelect?.() ?? undefined, ); return; } setMode(nextMode); onSelect?.(); if ( nextMode === APP_SIDEBAR_MODE.CHAT && !isLighthouseChatRoute(pathname) ) { router.push(LIGHTHOUSE_ROUTE.CHAT); } }; return (