"use client"; import Link from "next/link"; import { useEffect, useState, useRef, useCallback } from "react"; import { BookOpen, Grid3X3, Shield, Lightbulb, ChevronDown, Sparkles } from "lucide-react"; import { motion, AnimatePresence } from "framer-motion"; import { useTranslations } from "@/lib/i18n"; import { useSidebar } from "@/lib/SidebarContext"; interface SidebarItem { labelKey: string; href: string; isNew?: boolean; } interface SidebarGroup { titleKey: "intro" | "directory" | "standards" | "resources"; icon: typeof BookOpen; items: SidebarItem[]; } const sidebarGroups: SidebarGroup[] = [ { titleKey: "intro", icon: BookOpen, items: [ { labelKey: "whatAreSkills", href: "#what-are-skills" }, { labelKey: "howItWorks", href: "#how-it-works" }, { labelKey: "findingSkills", href: "#finding-skills" }, { labelKey: "compatibleAgents", href: "#compatible-agents" }, ], }, { titleKey: "directory", icon: Grid3X3, items: [ { labelKey: "aiPlatforms", href: "#directory" }, { labelKey: "cloudInfra", href: "#directory" }, { labelKey: "devTools", href: "#directory" }, { labelKey: "business", href: "#directory" }, { labelKey: "security", href: "#directory" }, ], }, { titleKey: "standards", icon: Shield, items: [ { labelKey: "qualityStandards", href: "#quality-standards" }, { labelKey: "usingSkills", href: "#using-skills" }, { labelKey: "creatingSkills", href: "#creating-skills" }, ], }, { titleKey: "resources", icon: Lightbulb, items: [ { labelKey: "tutorials", href: "#tutorials" }, { labelKey: "trends", href: "#trends", isNew: true }, { labelKey: "faq", href: "#faq" }, { labelKey: "contributing", href: "#contributing" }, ], }, ]; // Section IDs mapped from hrefs for IntersectionObserver const sectionIds = [ "what-are-skills", "how-it-works", "finding-skills", "compatible-agents", "directory", "quality-standards", "using-skills", "creating-skills", "tutorials", "trends", "faq", "contributing", ]; export default function WikiSidebar() { const [activeSection, setActiveSection] = useState("what-are-skills"); const [collapsed, setCollapsed] = useState>({}); const observerRef = useRef(null); const t = useTranslations(); const { isOpen } = useSidebar(); // IntersectionObserver for active section tracking useEffect(() => { observerRef.current = new IntersectionObserver( (entries) => { const visible = entries .filter((e) => e.isIntersecting) .sort((a, b) => a.boundingClientRect.top - b.boundingClientRect.top); if (visible.length > 0) { setActiveSection(visible[0].target.id); } }, { rootMargin: "-80px 0px -60% 0px", threshold: 0.1 } ); sectionIds.forEach((id) => { const el = document.getElementById(id); if (el) observerRef.current!.observe(el); }); return () => observerRef.current?.disconnect(); }, []); const toggleGroup = useCallback((key: string) => { setCollapsed((prev) => ({ ...prev, [key]: !prev[key] })); }, []); const getLabel = (key: string): string => { return (t.sidebar as Record)[key] ?? key; }; const isItemActive = (href: string): boolean => { const id = href.replace("#", ""); if (id === "directory") { return activeSection === "directory"; } return activeSection === id; }; return ( ); }