"use client";

import { Suspense } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
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="text-stagger"
                defaultTextAnimation="entrance-slide"
                borderRadius="soft"
                contentWidth="mediumLarge"
                sizing="medium"
                background="noiseDiagonalGradient"
                cardStyle="layered-gradient"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="layered"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            navItems={[{ name: "Home", id: "/" }, { name: "Shop", id: "/shop" }]}
                            button={{ text: "Cart", onClick: () => console.log("Cart clicked") }}
                            brandName="Royal Parlor"
                            className="relative z-50"
                            containerClassName="py-4"
                        />
                    </div>
                    <div id="loading-state" data-section="loading-state">
                        <main className="min-h-screen flex items-center justify-center pt-20">
                            <p className="text-foreground">Loading products...</p>
                        </main>
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="mediumLarge"
            sizing="medium"
            background="noiseDiagonalGradient"
            cardStyle="layered-gradient"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="layered"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        navItems={[{ name: "Home", id: "/" }, { name: "Shop", id: "/shop" }]}
                        button={{ text: "Cart", onClick: () => console.log("Cart clicked") }}
                        brandName="Royal Parlor"
                        className="relative z-50"
                        containerClassName="py-4"
                    />
                </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>
    );
}
