"use client"; import Image from "next/image"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { useEffect, useState, type ReactNode } from "react"; import { useAppShell } from "@/context/AppShellContext"; import { BookOpen, BookText, Brain, ChevronDown, Github, HeartHandshake, LayoutGrid, Library, MessageSquare, PanelLeftClose, PanelLeftOpen, PenLine, Settings, type LucideIcon, } from "lucide-react"; import { useTranslation } from "react-i18next"; import SessionList from "@/components/SessionList"; import { VersionBadge } from "@/components/sidebar/VersionBadge"; import type { SessionSummary } from "@/lib/session-api"; import { Tooltip } from "@/components/ui/Tooltip"; interface NavEntry { href: string; label: string; icon: LucideIcon; tooltipKey?: string; } const PRIMARY_NAV: NavEntry[] = [ { href: "/chat", label: "Chat", icon: MessageSquare, tooltipKey: "Chat tooltip", }, { href: "/partners", label: "Partners", icon: HeartHandshake, tooltipKey: "Partners tooltip", }, { href: "/co-writer", label: "Co-Writer", icon: PenLine, tooltipKey: "Co-Writer tooltip", }, { href: "/book", label: "Book", icon: Library, tooltipKey: "Book tooltip" }, { href: "/knowledge", label: "Knowledge", icon: BookOpen, tooltipKey: "Knowledge tooltip", }, // Mastery Path (/learning) is hidden from the product nav for now — the // route, its components and the backend stay in place so the feature can // be reworked and re-surfaced later. Re-add this entry to bring it back. { href: "/space", label: "Space", icon: LayoutGrid, tooltipKey: "Space tooltip", }, { href: "/memory", label: "Memory", icon: Brain, tooltipKey: "Memory tooltip", }, ]; const SECONDARY_NAV: NavEntry[] = [ { href: "/settings", label: "Settings", icon: Settings }, ]; const GITHUB_REPO_URL = "https://github.com/HKUDS/DeepTutor"; const DOCS_URL = "https://deeptutor.info/"; const RECENTS_COLLAPSED_KEY = "deeptutor.sidebar.recentsCollapsed"; interface SidebarShellProps { sessions?: SessionSummary[]; activeSessionId?: string | null; loadingSessions?: boolean; showSessions?: boolean; /** Clicking the Chat nav item resets to a fresh session via this handler. */ onNewChat?: () => void; onSelectSession?: (sessionId: string) => void | Promise; onRenameSession?: (sessionId: string, title: string) => void | Promise; onDeleteSession?: (sessionId: string) => void | Promise; footerSlot?: ReactNode; } export function SidebarShell({ sessions = [], activeSessionId = null, loadingSessions = false, showSessions = false, onNewChat, onSelectSession, onRenameSession, onDeleteSession, footerSlot, }: SidebarShellProps) { const pathname = usePathname(); const router = useRouter(); const { t } = useTranslation(); const { sidebarCollapsed: collapsed, setSidebarCollapsed: setCollapsed } = useAppShell(); const [recentsCollapsed, setRecentsCollapsed] = useState(false); // Hydrate Recents collapse from localStorage after first render to stay SSR-safe. useEffect(() => { if (typeof window === "undefined") return; // eslint-disable-next-line react-hooks/set-state-in-effect setRecentsCollapsed( window.localStorage.getItem(RECENTS_COLLAPSED_KEY) === "1", ); }, []); const toggleRecents = () => { setRecentsCollapsed((prev) => { const next = !prev; if (typeof window !== "undefined") { window.localStorage.setItem(RECENTS_COLLAPSED_KEY, next ? "1" : "0"); } return next; }); }; const handleChatClick = (event: React.MouseEvent) => { // Always reset to a fresh session (mirrors the old "New Chat" affordance); // let modifier-clicks fall through to default Link behavior so middle-click // open-in-new-tab still works. if (event.metaKey || event.ctrlKey || event.shiftKey || event.button === 1) return; event.preventDefault(); onNewChat?.(); router.push("/chat"); }; /* ---- Collapsed state ---- */ if (collapsed) { return ( ); } /* ---- Expanded state ---- */ return ( ); }