import { Bell, Search, AlertCircle, Mail, ChevronDown } from "lucide-react"; import { useEffect, useState, useRef } from "react"; import { apiClient } from "@/lib/api"; import { auth } from "@/lib/auth"; import Link from "next/link"; import { ThemeToggle } from "./ThemeToggle"; export function Header() { const [user, setUser] = useState(null); const [workspaces, setWorkspaces] = useState([]); const [activeWs, setActiveWs] = useState(null); const [dropdownOpen, setDropdownOpen] = useState(false); const dropdownRef = useRef(null); useEffect(() => { const fetchData = async () => { const [userRes, wsRes] = await Promise.all([ apiClient.get("/auth/me"), apiClient.get("/workspaces"), ]); if (userRes.success) setUser(userRes.data); if (wsRes.success && wsRes.data) { const wsList = Array.isArray(wsRes.data) ? wsRes.data : []; setWorkspaces(wsList); const currentWsId = auth.getWorkspaceId(); const current = wsList.find((w: any) => String(w.id) === currentWsId); setActiveWs(current || wsList[0] || null); // Auto-set workspace ID if not set if (!currentWsId && wsList.length > 0) { auth.setWorkspaceId(String(wsList[0].id)); } } }; fetchData(); }, []); // Close dropdown on outside click useEffect(() => { const handler = (e: MouseEvent) => { if (dropdownRef.current && !dropdownRef.current.contains(e.target as Node)) { setDropdownOpen(false); } }; document.addEventListener("mousedown", handler); return () => document.removeEventListener("mousedown", handler); }, []); const handleSwitch = (ws: any) => { auth.setWorkspaceId(String(ws.id)); setActiveWs(ws); setDropdownOpen(false); window.location.reload(); }; const wsInitials = (name: string) => name.split(" ").map((w) => w[0]).join("").toUpperCase().slice(0, 2) || "WS"; return (
{/* Verification Banner */} {user?.requires_email_verification && (
Please verify your email address. You have {user.verification_grace_remaining_days} days remaining in your grace period.
)}
{/* Theme Toggle - Currently locked out until dark mode UI is fully stable */} {/* */} {/*
*/} {/* Workspace Switcher */}
{dropdownOpen && workspaces.length > 1 && (

Switch Workspace

{workspaces.map((ws) => ( ))}
)}
); }