import { useLocation } from "react-router-dom";
import { documentationUrl } from "@libs/documentation";
import { getAdminGuides } from "@libs/admin-guides";
import DocumentationLinks from "./DocumentationLinks";

/** Contextual help stays available without leaving unsaved edits. */
const RelatedGuides = () => {
  const { pathname } = useLocation();
  const route = pathname.replace(/\/+$/, "") || "/";
  const guides = getAdminGuides(route).map(([path, label]) => ({
    href: documentationUrl(path),
    label,
  }));

  if (!guides.length) {
    return null;
  }

  return (
    <DocumentationLinks
      guides={guides}
      browseUrl={documentationUrl()}
      constrained={["/license", "/help", "/easy-setup"].includes(route)}
    />
  );
};

export default RelatedGuides;
