import BlogsData from "@comp/Blog/BlogsData/page";
import React from "react";

async function getData(sParams) {
  //

  const query = {
    page: 0,
    ...sParams,
  };

  const res = await fetch(
    `${process.env.NEXT_PUBLIC_API_URL}/blog?` +
      new URLSearchParams({ ...query }),
    {
      cache: "no-cache",
    }
    // ?page=${params.page ?? 0}
    // { cache: "no-cache" }
  );
  const post = await res.json();
  //

  console.log("post", post);

  return post;
}

async function getCaetgories() {
  const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/blog/category`);

  const post = await res.json();

  //
  return post;
}

const page = async ({ searchParams }) => {
  const data = await getData(searchParams);
  const dataCaetgories = await getCaetgories();
  //

  return <BlogsData data={data} dataCaetgories={dataCaetgories} />;
};

export default page;
