"use client";

import { Suspense } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import { useProductCatalog } from "@/hooks/useProductCatalog";

function ShopPageContent() {
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="icon-arrow"
                defaultTextAnimation="reveal-blur"
                borderRadius="soft"
                contentWidth="smallMedium"
                sizing="large"
                background="circleGradient"
                cardStyle="subtle-shadow"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Hero", id: "hero-section" },
                            { name: "About", id: "about-section" },
                            { name: "Feature", id: "features-section" },
                            { name: "Product", id: "products-section" },
                            { name: "Testimonial", id: "testimonials-section" },
                            { name: "Faq", id: "faq-section" },
                            { name: "Contact", id: "contact-section" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        brandName="CozyBeans Coffee"
                        bottomLeftText="Global Community"
                        bottomRightText="hello@cozybeans.com"
                        topBarClassName=""
                        button={{ text: "Cart", onClick: () => console.log("cart") }}
                    />
                    </div>
                    <main className="min-h-screen flex items-center justify-center pt-20">
                        <p className="text-foreground">Loading products...</p>
                    </main>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="icon-arrow"
            defaultTextAnimation="reveal-blur"
            borderRadius="soft"
            contentWidth="smallMedium"
            sizing="large"
            background="circleGradient"
            cardStyle="subtle-shadow"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                <NavbarStyleFullscreen
                    navItems={[
                        { name: "Home", id: "/" },
                        { name: "Hero", id: "hero-section" },
                        { name: "About", id: "about-section" },
                        { name: "Feature", id: "features-section" },
                        { name: "Product", id: "products-section" },
                        { name: "Testimonial", id: "testimonials-section" },
                        { name: "Faq", id: "faq-section" },
                        { name: "Contact", id: "contact-section" },
                        { name: "Shop", id: "/shop" }
                    ]}
                    brandName="CozyBeans Coffee"
                    bottomLeftText="Global Community"
                    bottomRightText="hello@cozybeans.com"
                    topBarClassName=""
                    button={{ text: "Cart", onClick: () => console.log("cart") }}
                />
                </div>
                <div id="product-catalog" data-section="product-catalog">
                <ProductCatalog
                    layout="page"
                    products={products}
                    searchValue={search}
                    onSearchChange={setSearch}
                    searchPlaceholder="Search products..."
                    filters={filters}
                    emptyMessage="No products found"
                />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

export default function ShopPage() {
    return (
        <Suspense>
            <ShopPageContent />
        </Suspense>
    );
}