import React, { useState, useEffect } from 'react'; import { api, NexusLogo } from '@nexus/shared'; const COLORS = { brand: "#1E40AF", brandLight: "#EFF6FF", brandMid: "#BFDBFE", gray50: "#F9FAFB", gray100: "#F3F4F6", gray200: "#E5E7EB", gray300: "#D1D5DB", gray400: "#9CA3AF", gray500: "#6B7280", gray600: "#4B5563", gray700: "#374151", gray800: "#1F2937", gray900: "#111827", }; interface SidebarProps { active: "dashboard" | "tickets" | "kb" | "analytics" | "thread" | "workspace"; setActive: (tab: any) => void; onNewTicket: () => void; onSettings: () => void; user: any; } export const Sidebar: React.FC = ({ active, setActive, onNewTicket, onSettings, user }) => { const [workspaces, setWorkspaces] = useState([]); const [currentWs, setCurrentWs] = useState(null); useEffect(() => { if (user?.workspace_id) { fetchWorkspaces(); } }, [user?.workspace_id]); const fetchWorkspaces = async () => { try { const resp = await api.get('workspace/list/'); setWorkspaces(resp.data); if (user?.workspace_id) { const activeWs = resp.data.find((w: any) => w.id === user.workspace_id) || resp.data[0]; setCurrentWs(activeWs); } } catch (err) { console.error("Failed to fetch workspaces:", err); } }; const nav = [ { id: "dashboard", label: "Dashboard", icon: "⊞" }, { id: "tickets", label: "My Tickets", icon: "◈" }, { id: "kb", label: "Knowledge Base", icon: "◉" }, { id: "workspace", label: "Workspace", icon: "🏢" }, { id: "analytics", label: "My Analytics", icon: "◫" }, ]; const handleWsChange = (wsId: string) => { const ws = workspaces.find(w => w.id === wsId); if (ws) { setCurrentWs(ws); // In a real app, we'd trigger a global state update or page refresh with the new ID console.log("Switching context to:", ws.name); } }; return ( ); };