"use client";

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

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

    const themeProviderProps = {
        defaultButtonVariant: "expand-hover",        defaultTextAnimation: "background-highlight",        borderRadius: "pill",        contentWidth: "compact",        sizing: "largeSmallSizeLargeTitles",        background: "circleGradient",        cardStyle: "gradient-radial",        primaryButtonStyle: "double-inset",        secondaryButtonStyle: "layered",        headingFontWeight: "light"
    };

    const navbarProps = {
        brandName: "No song",        navItems: [
            { name: "Home", id: "/" },
            { name: "Shop", id: "/shop" }
        ],
        button: { text: "Cart", onClick: () => console.log("Cart button clicked") }
    };

    if (isLoading) {
        return (
            <ThemeProvider {...themeProviderProps}>
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple {...navbarProps} />
                    </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 {...themeProviderProps}>
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple {...navbarProps} />
                </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>
    );
}
