import { forwardRef, useEffect, useRef, useState } from 'react' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import ComsatsLogo from '../ComsatsLogo' import { MessageRoleSticker } from './MessageRoleSticker' function AssistantAvatarIcon({ className = '' }) { return ( ) } function SendIcon({ className = '' }) { return ( ) } function DotsVerticalIcon({ className = '' }) { return ( ) } function CheckMiniIcon({ className = '' }) { return ( ) } function SparklesIcon({ className = '' }) { return ( ) } function MarkdownText({ content, tone = 'assistant' }) { const linkClass = tone === 'user' ? 'underline decoration-white/60 hover:decoration-white' : 'font-medium text-comsats-blue underline decoration-comsats-blue/25 underline-offset-2 hover:text-comsats-purple' const codeBg = tone === 'user' ? 'bg-white/20 text-white' : 'bg-slate-100 text-slate-900 ring-1 ring-slate-200/80' const codeBlockBg = tone === 'user' ? 'bg-black/25 text-white' : 'bg-slate-50 text-slate-900 ring-1 ring-slate-200/90' return ( (

{children}

), ul: ({ children }) => , ol: ({ children }) =>
    {children}
, li: ({ children }) =>
  • {children}
  • , a: ({ href, children }) => ( {children} ), strong: ({ children }) => ( {children} ), code: ({ inline, children }) => inline ? ( {children} ) : ( {children} ), }} > {content ?? ''}
    ) } const EMPTY_THREAD_STARTERS = [ 'What programs are offered at CUI Attock?', 'How do I apply for admissions?', 'Tell me about campus facilities and fees.', ] const ChatMain = forwardRef(function ChatMain( { chatId, chatTitle = 'Conversation', turns, loadingChat, loadingOlder, hasOlder, onLoadOlder, sending, tailBump, error, question, setQuestion, onSend, followUpSuggestions = [], suggestionsEnabled = true, onSuggestionsEnabledChange, webSearchEnabled = false, onWebSearchEnabledChange, onPickFollowUp, sidebarExpanded = true, collapsedSidebarRail = false, onOpenSidebar = () => {}, }, scrollRef, ) { const [sourceMenuOpen, setSourceMenuOpen] = useState(false) const sourceMenuWrapRef = useRef(null) useEffect(() => { if (!sourceMenuOpen) return function handlePointerDown(e) { const el = sourceMenuWrapRef.current if (el && !el.contains(e.target)) setSourceMenuOpen(false) } function handleKey(e) { if (e.key === 'Escape') setSourceMenuOpen(false) } document.addEventListener('mousedown', handlePointerDown) window.addEventListener('keydown', handleKey) return () => { document.removeEventListener('mousedown', handlePointerDown) window.removeEventListener('keydown', handleKey) } }, [sourceMenuOpen]) useEffect(() => { if (!chatId || loadingChat) return const el = scrollRef?.current if (!el) return const scrollToEnd = () => { el.scrollTo({ top: el.scrollHeight, behavior: 'smooth' }) } requestAnimationFrame(() => { requestAnimationFrame(scrollToEnd) }) }, [chatId, loadingChat, tailBump]) const showHeaderOpenSidebar = !sidebarExpanded && !collapsedSidebarRail const headerTools = (
    Follow-ups
    ) if (!chatId) { return (
    {showHeaderOpenSidebar ? ( ) : null} CUI Connect

    CUI Connect

    Open the sidebar to pick a chat or start fresh — admissions, programs, and campus questions welcome.

    ) } const showEmptyWelcome = !loadingChat && turns.length === 0 && !sending return (
    {showHeaderOpenSidebar ? ( ) : null}

    {chatTitle}

    CUI Connect · Knowledge assistant

    {headerTools}
    {loadingChat ? (

    Loading messages…

    ) : (
    {hasOlder ? (
    ) : null} {showEmptyWelcome ? (

    What would you like to know?

    I can help with programs, admissions, fees, and campus life. After you open a chat, use the ⋯ menu next to the message box to choose{' '} RAG (knowledge base) or{' '} Web search.

    Try one of these

    {EMPTY_THREAD_STARTERS.map((s) => ( ))}
    ) : null}
    {turns.map((turn) => { const key = turn.clientKey != null ? turn.clientKey : `pair-${turn.pairIndex ?? 'x'}` return (
    You:
    Assistant: {turn.pending ? ( Thinking… ) : (
    )}
    ) })}
    )}
    {error ? (
    {error}
    ) : null}