import React, { useState, useEffect } from 'react'; import { ChatWindow } from '@/components/ai/ChatWindow'; import { ResizablePanel } from '@/components/ui/ResizablePanel'; import { SuggestionList } from '@/components/ai/SuggestionSidebar'; import { createSession, fetchSessions } from '@/api/ai'; import { useUIStore } from '@/store/uiStore'; export function AISidebar() { const { aiSidebarCollapsed, toggleAISidebar, aiSidebarTab, setAISidebarTab } = useUIStore(); const [sessionId, setSessionId] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { (async () => { try { const sessions = await fetchSessions(true); if (sessions.length > 0) { setSessionId(sessions[0].id); } else { const session = await createSession({ is_sidebar: true, title: 'Sidebar Chat' }); setSessionId(session.id); } } catch (e) { console.error('AISidebar init error:', e); } finally { setLoading(false); } })(); }, []); // Collapsed: narrow icon strip (desktop only, hidden on mobile) if (aiSidebarCollapsed) { return (
); } const renderTabContent = () => { if (aiSidebarTab === 'proactive') { return ; } // chat tab if (loading) { return (
Laden...
); } if (sessionId) { return ; } return (
Session konnte nicht erstellt werden
); }; const tabBar = (
); // Expanded: Mobile = full width overlay, Desktop = resizable panel return ( <> {/* Mobile: full width overlay with back button */}
KI Assistent
{tabBar}
{renderTabContent()}
{/* Desktop: resizable panel */}
KI Assistent
{tabBar}
{renderTabContent()}
); }