"use client"; import { useEffect, useMemo, useState } from "react"; import { useTranslations } from "next-intl"; import Link from "next/link"; import { HelpCircleIcon } from "lucide-react"; import { Button, Sheet, SheetContent, SheetTrigger, SheetHeader, SheetTitle, SheetDescription, } from "../../../shadcnui"; import { usePageUrlGenerator } from "../../../client"; import { HowToService } from "../../how-to/data/HowToService"; import type { HowToInterface } from "../../how-to/data/HowToInterface"; export function HelpHint({ contextKey }: { contextKey: string }) { const t = useTranslations(); const generateUrl = usePageUrlGenerator(); const [open, setOpen] = useState(false); const [picked, setPicked] = useState(null); const [articles, setArticles] = useState([]); useEffect(() => { let active = true; HowToService.findPublished() .then((list) => active && setArticles(list)) .catch(() => active && setArticles([])); return () => { active = false; }; }, []); const matches = useMemo( () => articles.filter((a) => a.contextualKeys.includes(contextKey) && !a.draft), [articles, contextKey], ); if (matches.length === 0) return null; const active = picked ?? (matches.length === 1 ? matches[0] : null); return ( { setOpen(o); if (!o) setPicked(null); }} > }> {active ? active.name : t("help.hint.pickArticle")} {active?.summary ?? ""} {active ? (

{active.summary}

{t("help.hint.viewArticle")}
) : (
    {matches.map((a) => (
  • ))}
)}
); }