import { useState, useRef, useEffect } from "react"; import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; import { CircleHelp, X } from "lucide-react"; interface PageHelpProps { helpKey: string; /** * Optional route rendered as a link under the tips (#356), labelled by * `${helpKey}.help.linkLabel`. No close handler on click: navigating away * unmounts the page and the popover with it. */ linkTo?: string; } export function PageHelp({ helpKey, linkTo }: PageHelpProps) { const { t } = useTranslation(); const [isOpen, setIsOpen] = useState(false); const ref = useRef(null); // Close on outside click (same pattern as CategoryCombobox) useEffect(() => { if (!isOpen) return; const handler = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) { setIsOpen(false); } }; document.addEventListener("mousedown", handler); return () => document.removeEventListener("mousedown", handler); }, [isOpen]); const tips = t(`${helpKey}.help.tips`, { returnObjects: true }) as string[]; return (
{isOpen && (

{t(`${helpKey}.help.title`)}

    {Array.isArray(tips) && tips.map((tip, i) => (
  • • {tip}
  • ))}
{linkTo && ( {t(`${helpKey}.help.linkLabel`)} )}
)}
); }