import { Clock3, Folder, FolderOpen, LoaderCircle, Plus, Search, SquarePen, X } from "lucide-react" import { AgentAvatar } from "@/components/session/agent-avatar" import { useEffect, useRef, useState } from "react" import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { ScrollArea } from "@/components/ui/scroll-area" import { CreateAgentDialog } from "@/components/session/create-agent-dialog" import { PushNotificationButton } from "@/components/session/push-notification-button" import { SidebarChatList } from "@/components/session/sidebar-chat-list" import { compareSchedules, dateTimeLabel } from "@/components/session/schedule-utils" import { cn } from "@/lib/utils" import type { SessionShellState } from "@/components/session/session-shell" export function SessionSidebar({ shell }: { shell: SessionShellState }) { const [searchOpen, setSearchOpen] = useState(false) const [search, setSearch] = useState("") const [agentDialogOpen, setAgentDialogOpen] = useState(false) const [expandedProjects, setExpandedProjects] = useState([]) const visitedProjects = useRef(new Set()) const activeProjectPath = shell.activeWorkspace?.path useEffect(() => { if (activeProjectPath && !visitedProjects.current.has(activeProjectPath)) { visitedProjects.current.add(activeProjectPath) setExpandedProjects((current) => current.includes(activeProjectPath) ? current : [...current, activeProjectPath]) } }, [activeProjectPath]) const scheduled = shell.navigationView === "scheduled" const matches = (value: string) => value.toLocaleLowerCase().includes(search.trim().toLocaleLowerCase()) const projects = [ ...shell.workspaces, ...shell.recentWorkspaces.filter((recent) => !shell.workspaces.some((workspace) => workspace.path === recent.path)), ].filter((project) => matches(project.name)) const openProject = (id: string) => { const workspace = shell.workspaces.find((item) => item.id === id) if (workspace) { shell.selectWorkspace(workspace.id) shell.startNewChat() } else { const recent = shell.recentWorkspaces.find((item) => item.id === id) if (recent) void shell.openRecentWorkspace(recent) } shell.selectNavigationView("home") } return ( ) }