import { useState, useEffect } from "react"; import { ChevronLeft, ChevronRight, Rocket, Globe, Gauge, Link, Bell, AlertTriangle, Settings, FileText, } from "lucide-react"; import { useUserGuideTheme } from "./styles/useUserGuideTheme"; import "./ArticlePage.css"; // Map icon names to actual Lucide components const iconMap = { Rocket, Globe, Gauge, Link, Bell, AlertTriangle, Settings, FileText, }; const ArticlePage = ({ collection, article, onBack, onBackToHome, onNextArticle, onPrevArticle, nextArticle, prevArticle, tocItems, children, mode = "in-app", }) => { const { colors, typography, spacing, border, isDark } = useUserGuideTheme(); const IconComponent = iconMap[collection.icon] || Rocket; const isInApp = mode === "in-app"; const [activeSection, setActiveSection] = useState(""); // Track active section on scroll useEffect(() => { if (!tocItems || tocItems.length === 0) return; const handleScroll = () => { const sections = tocItems .map((item) => { const id = item.href.replace("#", ""); const element = document.getElementById(id); return { id: item.href, element }; }) .filter((s) => s.element); if (sections.length === 0) return; let currentSection = sections[0].id; for (const section of sections) { if (section.element) { const rect = section.element.getBoundingClientRect(); if (rect.top <= 150) { currentSection = section.id; } } } setActiveSection(currentSection); }; window.addEventListener("scroll", handleScroll, { passive: true }); document.addEventListener("scroll", handleScroll, { passive: true, capture: true }); handleScroll(); return () => { window.removeEventListener("scroll", handleScroll); document.removeEventListener("scroll", handleScroll, { capture: true }); }; }, [tocItems]); return (
{article.description}
{/* Table of Contents - at top */} {tocItems && tocItems.length > 0 && (