import { fetchPostsByTag } from "@/services/blogActions";
import { formatSection } from "@/utils/posts-utils";
import ResourceSection from "@/components/pages/client/resources/resource-section";

type Params = Promise<{ section: string }>;

export async function generateMetadata({ params }: { params: Params }) {
  const { section } = await params;

  return {
    title: `${formatSection(section)} | Resources`,
  };
}

async function getAllPostsByInternalTag({ section }: { section: string }) {
  const data = await fetchPostsByTag([`hash-resources-${section}`]);
  return data;
}

export default async function ResourcesSectionPage({
  params,
}: {
  params: Params;
}) {
  const { section } = await params;

  const allPostsBySection = await getAllPostsByInternalTag({
    section: section,
  });

  const { posts } = allPostsBySection;

  return <ResourceSection posts={posts} />;
}
