"use client"; import { useLocale, useTranslations } from "next-intl"; import { useState } from "react"; import InfiniteScroll from "react-infinite-scroll-component"; import HeroCarousel from "./Carousel"; import CategoryGrid from "./CategoryGrid"; import CollectionSection from "./ProductGrid"; import { useCategories, useCarousels, useCollections, useFavorites, } from "@/lib/hooks"; export default function HomePage() { const locale = useLocale(); const t = useTranslations("common"); const [visibleCount, setVisibleCount] = useState(10); const { data: categories, isLoading: categoriesLoading, isError: categoriesError, } = useCategories(); const { data: carousels, isLoading: carouselsLoading } = useCarousels(); const { data: collections, isLoading: collectionsLoading, isError: collectionsError, } = useCollections(); useFavorites(); const loadMore = () => { if (collections && visibleCount < collections.length) { setVisibleCount((prev) => Math.min(prev + 10, collections.length)); } }; const carouselItems = carousels?.map((c) => ({ title: c.title || "", image: c.image || c.thumbnail, url: c.link || null, })) || []; const visibleCollections = collections?.slice(0, visibleCount) || []; const hasMore = collections ? visibleCount < collections.length : false; return (
{!carouselsLoading && carouselItems.length > 0 && ( )} {collectionsError ? (

Failed to load collections. Please try again.

) : collectionsLoading ? (
{Array.from({ length: 3 }).map((_, i) => (
{Array.from({ length: 5 }).map((_, j) => (
))}
))}
) : (

{t("loading")}

} endMessage={

✓ {t("all_collections_loaded")}

} scrollThreshold={0.8} >
{visibleCollections.map((collection) => ( ))}
)}
); }