---
import ArticlesView from "../../../components/ArticlesView.astro";
import { getPublishedArticles, getCategoryNames, getCategories, pageSlice, lastPageOf } from "../../../lib/articles";

export async function getStaticPaths() {
  const articles = await getPublishedArticles();
  return Array.from({ length: Math.max(0, lastPageOf(articles.length) - 1) }, (_, index) => ({
    params: { page: String(index + 2) },
  }));
}

const all = await getPublishedArticles();
const page = Number(Astro.params.page);
---
<ArticlesView items={pageSlice(all, page)} categories={getCategories(all, await getCategoryNames())} totalCount={all.length} activeSlug={null} activeName={null} currentPage={page} lastPage={lastPageOf(all.length)} basePath="/articles" />
