"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useEffect, useState } from "react"; import { useLive } from "@/lib/live"; import { Activity, Bot, PlugZap, Contact, FolderKanban, Gauge, GitBranch, Megaphone, House, KeyRound, MessagesSquare, ScrollText, LifeBuoy, LogOut, MessageCircleWarning, Search, Server, Settings, ShieldCheck, Sparkles, SquareTerminal, Users, type LucideIcon } from "lucide-react"; import { Brand } from "@/components/Brand"; import { ThemeToggle } from "@/components/ThemeToggle"; import { LanguageSwitcher } from "@/components/I18n"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { useT } from "@/components/I18n"; import { m } from "@peppa/shared/i18n"; interface Item { href: string; label: string; icon: LucideIcon; match: (p: string) => boolean; count?: "questions" | "waitingRunners" | "chats" | "feedback"; /** Superadmin only (PEP-68, PEP-67; others get 404 on the URL too); desktop panel only — on phones it is linked from Settings. */ admin?: boolean; /** Not in the phone tab bar (six tabs fit; PEP-62 added «Чаты»). */ desktopOnly?: boolean; /** PEP-119: only in «Инженер» mode (terminals and other tools of a developer). */ engineer?: boolean; } const ITEMS: Item[] = [ { href: "/", label: m("Главная"), icon: House, match: (p) => p === "/", count: "questions" }, { href: "/chats", label: m("Чаты"), icon: MessagesSquare, match: (p) => p.startsWith("/chats"), count: "chats" }, { href: "/projects", label: m("Проекты"), icon: FolderKanban, match: (p) => p.startsWith("/projects") || p.startsWith("/p/") || p.startsWith("/t/") }, // glossary-ignore: PEP-257, терминалы агентов — пункт только в виде «Инженер» { href: "/sessions", label: m("Сессии"), icon: SquareTerminal, match: (p) => p.startsWith("/sessions"), desktopOnly: true, engineer: true }, { href: "/runners", label: m("Работа агентов"), icon: Bot, match: (p) => p.startsWith("/runners"), count: "waitingRunners", engineer: true }, { href: "/connections", label: m("Подключения"), icon: PlugZap, match: (p) => p.startsWith("/connections"), desktopOnly: true }, { href: "/team", label: m("Команда"), icon: Contact, match: (p) => p.startsWith("/team"), desktopOnly: true }, { href: "/welcome", label: m("О FORGE"), icon: Sparkles, match: (p) => p.startsWith("/welcome"), desktopOnly: true }, { href: "/help", label: m("Помощь"), icon: LifeBuoy, match: (p) => p.startsWith("/help") }, { href: "/dashboard", label: m("Дашборд"), icon: Gauge, match: (p) => p.startsWith("/dashboard"), admin: true }, { href: "/subscriptions", label: m("Подписки"), icon: KeyRound, match: (p) => p.startsWith("/subscriptions"), admin: true }, { href: "/secrets", label: m("Секреты"), icon: ShieldCheck, match: (p) => p.startsWith("/secrets"), admin: true }, { href: "/gitea", label: m("Gitea"), icon: GitBranch, match: (p) => p.startsWith("/gitea"), admin: true }, { href: "/observability", label: m("Observability"), icon: Activity, match: (p) => p.startsWith("/observability"), admin: true }, { href: "/hosts", label: m("Хосты"), icon: Server, match: (p) => p.startsWith("/hosts"), admin: true }, { href: "/journal", label: m("Журнал"), icon: ScrollText, match: (p) => p.startsWith("/journal"), admin: true }, { href: "/platform", label: m("Платформа"), icon: Megaphone, match: (p) => p.startsWith("/platform"), admin: true }, { href: "/feedback", label: m("Обращения"), icon: MessageCircleWarning, match: (p) => p.startsWith("/feedback"), count: "feedback", admin: true }, { href: "/users", label: m("Пользователи"), icon: Users, match: (p) => p.startsWith("/users"), admin: true }, { href: "/settings", label: m("Настройки"), icon: Settings, match: (p) => p.startsWith("/settings") }, ]; const COUNT_TITLE = { questions: m("{n} вопросов ждут вас"), waitingRunners: m("{n} агентов ждут вас"), chats: m("{n} новых сообщений в обсуждениях"), feedback: m("{n} обращений ждут решения") }; /** Left panel on desktop; on phones a top bar plus a bottom tab bar (PEP-38): sections with «ждут вас» counters, theme, user. */ export function Sidebar({ login, avatarUrl, counts: initialCounts, superadmin = false, engineer = false }: { login: string; avatarUrl: string | null; counts: Record<"questions" | "waitingRunners" | "chats" | "feedback", number>; superadmin?: boolean; engineer?: boolean }) { const path = usePathname(); const t = useT(); // PEP-225: the «ждут вас» counters follow the live channel (`attention`) without a re-render. const [live, setLive] = useState>({}); useEffect(() => setLive({}), [initialCounts]); useLive("attention", (e) => { if (e.type !== "data") return; const d = e.data as { questions?: number; waitingRunners?: number; chats?: number }; setLive({ questions: d.questions, waitingRunners: d.waitingRunners, chats: d.chats }); }); const counts = { ...initialCounts, ...Object.fromEntries(Object.entries(live).filter(([, v]) => typeof v === "number")) }; const items = ITEMS.filter((i) => (!i.admin || superadmin) && (!i.engineer || engineer)); // The phone tab bar holds what is left after the desktop-only and admin sections: 5 or 6 tabs. const phoneTabs = items.filter((i) => !i.admin && !i.desktopOnly).length; return (
{/* PEP-52: the palette listens for clicks on [data-open-palette]. */}
{/* PEP-136: the language is one click away on every page, not only in «Настройки». */}
{avatarUrl && } {login}
); }