import Hero from "@/components/home/Hero";
import Brands from "@/components/home/Brands";
import Offers from "@/components/home/Offers";
import Categories from "@/components/home/Categories";
import HomeProductsGrid from "@/components/common/HomeProductsGrid";
import {
  getFeaturedProducts,
  getBestSellerProducts,
  getNewArrivalProducts,
} from "@/lib/actions/products";
import { listBanners } from "@/lib/actions/catalog";

export const dynamic = "force-dynamic";

export default async function Home() {
  const [featured, bestSellers, newArrivals, banners] = await Promise.all([
    getFeaturedProducts(10),
    getBestSellerProducts(10),
    getNewArrivalProducts(10),
    listBanners(),
  ]);

  const sliderBanners = banners.filter((banner) => banner.type === "SLIDER");
  const bottomBanners = banners.filter((banner) => banner.type === "BOTTOM");

  return (
    <>
      <Hero banners={sliderBanners} />
      <HomeProductsGrid
        products={featured}
        href="/products"
        title="Featured Products"
      />
      <HomeProductsGrid
        products={bestSellers}
        href="/products"
        title="Best Sellers"
      />
      <Categories />
      <HomeProductsGrid
        products={newArrivals}
        href="/products"
        title="New Arrivals"
      />
      <Offers banners={bottomBanners} />
      <Brands />
    </>
  );
}
