import { useEffect, useState } from "react"; import { Home, Bookmark, Settings, LogOut, Bell, Sun, Moon, Monitor, Folder, LogIn, PenSquare, MessageSquareText, Highlighter, Compass, } from "lucide-react"; import { useStore } from "@nanostores/react"; import { $user, logout } from "../../store/auth"; import { $theme, cycleTheme } from "../../store/theme"; import { getUnreadNotificationCount } from "../../api/client"; import { Avatar, CountBadge } from "../ui"; import { useTranslation } from "react-i18next"; interface SidebarProps { currentPath?: string; onNavigate?: (path: string) => void; } export default function Sidebar({ currentPath: initialPath, onNavigate, }: SidebarProps) { const { t } = useTranslation(); const user = useStore($user); const theme = useStore($theme); const currentPath = initialPath || "/"; const [unreadCount, setUnreadCount] = useState(0); useEffect(() => { if (!user) return; const checkNotifications = async () => { const count = await getUnreadNotificationCount(); setUnreadCount(count); }; checkNotifications(); const interval = setInterval(checkNotifications, 30000); return () => clearInterval(interval); }, [user]); const publicNavItems = [ { icon: Home, label: t("nav.feed"), href: "/home", badge: undefined }, { icon: Compass, label: t("nav.discover"), href: "/discover", badge: undefined, }, { icon: MessageSquareText, label: t("nav.annotations"), href: "/annotations", badge: undefined, }, { icon: Highlighter, label: t("nav.highlights"), href: "/highlights", badge: undefined, }, { icon: Bookmark, label: t("nav.bookmarks"), href: "/bookmarks", badge: undefined, }, ]; const authNavItems = [ { icon: Home, label: t("nav.feed"), href: "/home" }, { icon: Compass, label: t("nav.discover"), href: "/discover" }, { icon: Bell, label: t("nav.activity"), href: "/notifications", badge: unreadCount, }, { icon: MessageSquareText, label: t("nav.annotations"), href: "/annotations", }, { icon: Highlighter, label: t("nav.highlights"), href: "/highlights" }, { icon: Bookmark, label: t("nav.bookmarks"), href: "/bookmarks" }, { icon: Folder, label: t("nav.collections"), href: "/collections" }, ]; const navItems = user ? authNavItems : publicNavItems; const themeLabel = theme === "light" ? t("nav.themeLight") : theme === "dark" ? t("nav.themeDark") : t("nav.themeSystem"); return ( ); }