"use client";
import CardWrapper from "@/components/TopLevel/CardList/CardWrapper/CardWrapper";
import Pagination from "@/components/Shared/Pagination/Pagination";
import { useEffect, useState } from "react";
import { getBlogPosts } from "@/lib/Api";

export default function Home() {
  const [currentPage, setCurrentPage] = useState(1);
  const [posts, setPosts] = useState<any>();
  useEffect(() => {
    fetchPost();
  }, []);

  const fetchPost = async () => {
    try {
      const response = await getBlogPosts();
      console.log("response", response);
      setPosts(response);
    } catch (err) {
      console.log(err, "error while fetching data");
    }
  };
  const handlePageChange = (page: any) => {
    setCurrentPage(page);
  };
  return (
    <>
      <CardWrapper cardData={posts} />
      <Pagination
        currentPage={currentPage}
        totalPages={8}
        onPageChange={handlePageChange}
      />
    </>
  );
}
