import { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { Link, useLocation } from "react-router-dom"; import { Rocket, LayoutDashboard, Upload, ArrowLeftRight, Tags, SlidersHorizontal, PiggyBank, BarChart3, Settings, ArrowLeft, Lightbulb, ListChecks, Footprints, Printer, } from "lucide-react"; const SECTIONS = [ { key: "gettingStarted", icon: Rocket }, { key: "dashboard", icon: LayoutDashboard }, { key: "import", icon: Upload }, { key: "transactions", icon: ArrowLeftRight }, { key: "categories", icon: Tags }, { key: "adjustments", icon: SlidersHorizontal }, { key: "budget", icon: PiggyBank }, { key: "reports", icon: BarChart3 }, { key: "settings", icon: Settings }, ] as const; export default function DocsPage() { const { t } = useTranslation(); const location = useLocation(); const [activeSection, setActiveSection] = useState(SECTIONS[0].key); const sectionRefs = useRef>({}); const contentRef = useRef(null); // Scroll spy via IntersectionObserver useEffect(() => { const container = contentRef.current; if (!container) return; const observer = new IntersectionObserver( (entries) => { for (const entry of entries) { if (entry.isIntersecting) { setActiveSection(entry.target.id); } } }, { root: container, rootMargin: "-10% 0px -80% 0px", threshold: 0, } ); for (const { key } of SECTIONS) { const el = sectionRefs.current[key]; if (el) observer.observe(el); } return () => observer.disconnect(); }, []); // Handle initial anchor from URL useEffect(() => { const hash = location.hash.replace("#", ""); if (hash && sectionRefs.current[hash]) { requestAnimationFrame(() => { sectionRefs.current[hash]?.scrollIntoView({ behavior: "smooth" }); }); } }, [location.hash]); const scrollToSection = (key: string) => { sectionRefs.current[key]?.scrollIntoView({ behavior: "smooth" }); }; return (
{/* Sidebar TOC */} {/* Scrollable content */}

{t("docs.title")}

{SECTIONS.map(({ key, icon: Icon }) => (
{ sectionRefs.current[key] = el; }} className="bg-[var(--card)] border border-[var(--border)] rounded-xl p-6 space-y-4" > {/* Section header */}

{t(`docs.${key}.title`)}

{/* Overview */}

{t(`docs.${key}.overview`)}

{/* Features */}

{t("docs.features")}

    {( t(`docs.${key}.features`, { returnObjects: true, }) as string[] ).map((item, i) => (
  • {item}
  • ))}
{/* Steps */}

{key === "gettingStarted" ? t("docs.quickStart") : t("docs.howTo")}

    {( t(`docs.${key}.steps`, { returnObjects: true, }) as string[] ).map((item, i) => (
  1. {item}
  2. ))}
{/* Tips */}

{t("docs.tipsHeader")}

    {( t(`docs.${key}.tips`, { returnObjects: true, }) as string[] ).map((item, i) => (
  • {item}
  • ))}
))}
); }