import classNames from '~/lib/classNames' import StyledButton from '../StyledButton' import { router, usePage } from '@inertiajs/react' import { ChatSession } from '../../../types/chat' import { IconMessage } from '@tabler/icons-react' import { useState } from 'react' import KnowledgeBaseModal from './KnowledgeBaseModal' interface ChatSidebarProps { sessions: ChatSession[] activeSessionId: string | null onSessionSelect: (id: string) => void onNewChat: () => void onClearHistory: () => void isInModal?: boolean } export default function ChatSidebar({ sessions, activeSessionId, onSessionSelect, onNewChat, onClearHistory, isInModal = false, }: ChatSidebarProps) { const { aiAssistantName } = usePage<{ aiAssistantName: string }>().props const [isKnowledgeBaseModalOpen, setIsKnowledgeBaseModalOpen] = useState( () => new URLSearchParams(window.location.search).get('knowledge_base') === 'true' ) function handleCloseKnowledgeBase() { setIsKnowledgeBaseModalOpen(false) const params = new URLSearchParams(window.location.search) if (params.has('knowledge_base')) { params.delete('knowledge_base') const newUrl = [window.location.pathname, params.toString()].filter(Boolean).join('?') window.history.replaceState(window.history.state, '', newUrl) } } return (