import type { Metadata } from "next";
import { SitePage } from "@/app/(site)/_components/SitePage";
import { SiteHeader } from "@/app/(site)/_components/SiteHeader";
import { SiteFooter } from "@/app/(site)/_components/SiteFooter";
import { ArticleListing } from "@/app/(site)/_components/articles/ArticleListing";
import { THOUGHT_LEADERSHIP_DEFAULTS } from "@/app/(site)/_components/pages/thought-leadership-articles/defaults";
import { THOUGHT_LEADERSHIP_SECTIONS } from "@/app/(site)/_components/pages/thought-leadership-articles/sections";
import { renderSections } from "@/app/(site)/_components/pages/render";
import { ARTICLES_PER_PAGE } from "@/app/(site)/_lib/articles";
import { getArticleCategories, getArticles, getPage } from "@/app/(site)/_lib/cms";
import type { ArticleListingContent } from "@/app/(site)/_lib/pageContent";

export const metadata: Metadata = {
  title: "Thought Leadership & Articles — Unionists Group",
};

export default async function Page() {
  // The first page of "All" and the tabs are rendered here; other tabs and pages load in the browser.
  const [data, list, categories] = await Promise.all([getPage("thought-leadership-articles"), getArticles(`limit=${ARTICLES_PER_PAGE}&page=1`), getArticleCategories()]);
  const sections = { ...THOUGHT_LEADERSHIP_SECTIONS, articles: (c: ArticleListingContent) => <ArticleListing c={c} initial={{ list, categories }} /> };
  return (
    <SitePage>
      <a className="skip-link" href="#main">
        Skip to main content
      </a>{" "}
      <SiteHeader active="/roadmap" activeItem="/thought-leadership-articles" />
      <main id="main">{renderSections("thought-leadership-articles", data, THOUGHT_LEADERSHIP_DEFAULTS, sections)}</main>
      <SiteFooter />
    </SitePage>
  );
}
