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';
import { useTranslation } from 'react-i18next';
import { useUsers, useGroups } from '@/api/hooks';
import { Avatar } from '@/components/ui/Avatar';
import { Bell, Bot, ChevronLeft, ChevronRight, Lightbulb, MessageSquare, Users, X } from 'lucide-react';
const robotIcon = (className: string) => (
);
const bellIcon = (className: string) => (
);
const bulbIcon = (className: string) => (
);
const teamIcon = (className: string) => (
);
const chatBubbleIcon = (className: string) => (
);
const chevronRightIcon = (
);
interface TabDef {
key: 'proactive' | 'chat' | 'notifications' | 'team' | 'chatroom';
label: string;
icon: (cls: string) => React.ReactNode;
testId: string;
}
function TeamPanel() {
const { data: usersData, isLoading: usersLoading } = useUsers();
const { data: groupsData, isLoading: groupsLoading } = useGroups();
const users: any[] = usersData?.items || [];
const groups: any[] = groupsData?.items || [];
return (
Mitarbeiter
{usersLoading ? (
Laden...
) : users.length === 0 ? (
Keine Mitarbeiter
) : (
)}
Gruppen
{groupsLoading ? (
Laden...
) : groups.length === 0 ? (
Keine Gruppen
) : (
{groups.map((g) => (
{g.name}
{g.description &&
{g.description}
}
))}
)}
);
}
function ChatPanel() {
return (
Chat-Sidebar - Coming Soon
);
}
export function AISidebar() {
const { t } = useTranslation();
const { aiSidebarCollapsed, toggleAISidebar, aiSidebarTab, setAISidebarTab, notifications, removeNotification } = 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);
}
})();
}, []);
const tabs: TabDef[] = [
{ key: 'chat', label: 'KI Chat', icon: robotIcon, testId: 'ai-sidebar-tab-chat' },
{ key: 'proactive', label: 'Live KI', icon: bulbIcon, testId: 'ai-sidebar-tab-proactive' },
{ key: 'notifications', label: t('topbar.notifications'), icon: bellIcon, testId: 'ai-sidebar-tab-notifications' },
{ key: 'team', label: 'Team', icon: teamIcon, testId: 'ai-sidebar-tab-team' },
{ key: 'chatroom', label: 'Chat', icon: chatBubbleIcon, testId: 'ai-sidebar-tab-chatroom' },
];
const activeTab = tabs.find((tab) => tab.key === aiSidebarTab) || tabs[0];
// Collapsed: narrow icon strip (desktop only, hidden on mobile)
if (aiSidebarCollapsed) {
return (
{tabs.map((tab) => (
))}
);
}
const renderTabContent = () => {
if (aiSidebarTab === 'proactive') {
return ;
}
if (aiSidebarTab === 'notifications') {
return (
{notifications.length === 0 && (
Keine Benachrichtigungen
)}
{notifications.map((msg, i) => (
{msg}
))}
);
}
if (aiSidebarTab === 'team') {
return ;
}
if (aiSidebarTab === 'chatroom') {
return ;
}
// chat tab
if (loading) {
return (
Laden...
);
}
if (sessionId) {
return ;
}
return (
Session konnte nicht erstellt werden
);
};
const iconStrip = (
{tabs.map((tab) => (
))}
);
// Expanded: Mobile = full width overlay, Desktop = resizable panel
return (
<>
{/* Mobile: full width overlay with back button */}
{iconStrip}
{activeTab.label}
{renderTabContent()}
{/* Desktop: resizable panel */}
{iconStrip}
{activeTab.label}
{renderTabContent()}
>
);
}