"use client"; import { PenSquare } from "lucide-react"; import { useTranslations } from "next-intl"; import { useState } from "react"; import { Skeleton } from "@/components/ui/skeleton"; import { cn } from "@/lib/utils"; import { SIDEBAR_MIN_WIDTH } from "../../hooks/useSidebarResize"; import type { ChatItem, NavItem, PageUsage, SearchSpace, User } from "../../types/layout.types"; import { ChatListItem } from "./ChatListItem"; import { NavSection } from "./NavSection"; import { PageUsageDisplay } from "./PageUsageDisplay"; import { SidebarButton } from "./SidebarButton"; import { SidebarCollapseButton } from "./SidebarCollapseButton"; import { SidebarHeader } from "./SidebarHeader"; import { SidebarSection } from "./SidebarSection"; import { SidebarUserProfile } from "./SidebarUserProfile"; function ChatListItemSkeleton() { return (
); } interface SidebarProps { searchSpace: SearchSpace | null; isCollapsed?: boolean; onToggleCollapse?: () => void; navItems: NavItem[]; onNavItemClick?: (item: NavItem) => void; chats: ChatItem[]; sharedChats?: ChatItem[]; activeChatId?: number | null; onNewChat: () => void; onChatSelect: (chat: ChatItem) => void; onChatRename?: (chat: ChatItem) => void; onChatDelete?: (chat: ChatItem) => void; onChatArchive?: (chat: ChatItem) => void; onViewAllSharedChats?: () => void; onViewAllPrivateChats?: () => void; isSharedChatsPanelOpen?: boolean; isPrivateChatsPanelOpen?: boolean; user: User; onSettings?: () => void; onManageMembers?: () => void; onUserSettings?: () => void; onLogout?: () => void; pageUsage?: PageUsage; theme?: string; setTheme?: (theme: "light" | "dark" | "system") => void; className?: string; isLoadingChats?: boolean; disableTooltips?: boolean; sidebarWidth?: number; isResizing?: boolean; } export function Sidebar({ searchSpace, isCollapsed = false, onToggleCollapse, navItems, onNavItemClick, chats, sharedChats = [], activeChatId, onNewChat, onChatSelect, onChatRename, onChatDelete, onChatArchive, onViewAllSharedChats, onViewAllPrivateChats, isSharedChatsPanelOpen = false, isPrivateChatsPanelOpen = false, user, onSettings, onManageMembers, onUserSettings, onLogout, pageUsage, theme, setTheme, className, isLoadingChats = false, disableTooltips = false, sidebarWidth = SIDEBAR_MIN_WIDTH, isResizing = false, }: SidebarProps) { const t = useTranslations("sidebar"); const [openDropdownChatId, setOpenDropdownChatId] = useState(null); return (
{/* Header - search space name or collapse button when collapsed */} {isCollapsed ? (
{})} disableTooltip={disableTooltips} />
) : (
{})} disableTooltip={disableTooltips} />
)} {/* New chat button */}
{/* Chat sections - fills available space */} {isCollapsed ? (
) : (
{/* Shared Chats Section - takes only space needed, max 50% */} {!disableTooltips && isSharedChatsPanelOpen ? t("hide") : t("show_all")} ) : undefined } > {isLoadingChats ? (
) : sharedChats.length > 0 ? (
4 ? "pb-8" : ""}`} > {sharedChats.slice(0, 20).map((chat) => ( setOpenDropdownChatId(open ? chat.id : null)} onClick={() => onChatSelect(chat)} onRename={() => onChatRename?.(chat)} onArchive={() => onChatArchive?.(chat)} onDelete={() => onChatDelete?.(chat)} /> ))}
{/* Gradient fade indicator when more than 4 items */} {sharedChats.length > 4 && (
)}
) : (

{t("no_shared_chats")}

)} {/* Private Chats Section - fills remaining space */} {!disableTooltips && isPrivateChatsPanelOpen ? t("hide") : t("show_all")} ) : undefined } > {isLoadingChats ? (
) : chats.length > 0 ? (
4 ? "pb-8" : ""}`} > {chats.slice(0, 20).map((chat) => ( setOpenDropdownChatId(open ? chat.id : null)} onClick={() => onChatSelect(chat)} onRename={() => onChatRename?.(chat)} onArchive={() => onChatArchive?.(chat)} onDelete={() => onChatDelete?.(chat)} /> ))}
{/* Gradient fade indicator when more than 4 items */} {chats.length > 4 && (
)}
) : (

{t("no_chats")}

)}
)} {/* Footer */}
{/* Platform navigation */} {navItems.length > 0 && ( )} {pageUsage && !isCollapsed && ( )}
); }