"use client";

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

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="hover-magnetic"
                defaultTextAnimation="background-highlight"
                borderRadius="soft"
                contentWidth="smallMedium"
                sizing="mediumSizeLargeTitles"
                background="grid"
                cardStyle="inset"
                primaryButtonStyle="flat"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="Bella Italia"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            button={{ text: "Cart", onClick: () => console.log("Cart state not available on this page") }}
                            className="py-4 px-6"
                            buttonClassName="px-5 py-2"
                        />
                    </div>
                    <div id="loading-section" data-section="loading-section">
                        <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="hover-magnetic"
            defaultTextAnimation="background-highlight"
            borderRadius="soft"
            contentWidth="smallMedium"
            sizing="mediumSizeLargeTitles"
            background="grid"
            cardStyle="inset"
            primaryButtonStyle="flat"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="Bella Italia"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        button={{ text: "Cart", onClick: () => console.log("Cart state not available on this page") }}
                        className="py-4 px-6"
                        buttonClassName="px-5 py-2"
                    />
                </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>
    );
}
