"use client";

import { Suspense } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
import FooterSimple from '@/components/sections/footer/FooterSimple';
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="hover-bubble"
                defaultTextAnimation="reveal-blur"
                borderRadius="soft"
                contentWidth="mediumLarge"
                sizing="largeSmall"
                background="noise"
                cardStyle="glass-depth"
                primaryButtonStyle="radial-glow"
                secondaryButtonStyle="glass"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="Maxximize"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Services","id":"services"},
                            {"name":"Results","id":"results"},
                            {"name":"Products","id":"products"},
                            {"name":"Contact","id":"contact"}
                        ]}
                        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>
                    <div id="footer" data-section="footer">
                    <FooterSimple
                        columns={[
                            {"title":"Navigate","items":[{"label":"Home","href":"/"},{"label":"Services","href":"#services"},{"label":"Products","href":"#products"},{"label":"Results","href":"#results"}]},
                            {"title":"Resources","items":[{"label":"Blog","href":"/blog"},{"label":"FAQ","href":"#faq"},{"label":"Community","href":"#"},{"label":"Support","href":"#contact"}]},
                            {"title":"Legal","items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"Contact Us","href":"#contact"},{"label":"Disclaimer","href":"#"}]}
                        ]}
                        bottomLeftText="© 2025 Maxximize. All rights reserved."
                        bottomRightText="Transforming men, one result at a time"
                    />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="reveal-blur"
            borderRadius="soft"
            contentWidth="mediumLarge"
            sizing="largeSmall"
            background="noise"
            cardStyle="glass-depth"
            primaryButtonStyle="radial-glow"
            secondaryButtonStyle="glass"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                <NavbarLayoutFloatingInline
                    brandName="Maxximize"
                    navItems={[
                        {"name":"Home","id":"/"},
                        {"name":"Services","id":"services"},
                        {"name":"Results","id":"results"},
                        {"name":"Products","id":"products"},
                        {"name":"Contact","id":"contact"}
                    ]}
                    button={{ text: "Cart", onClick: () => console.log("cart") }}
                />
                </div>
                <div id="productCatalog" data-section="productCatalog">
                <ProductCatalog
                    layout="page"
                    products={products}
                    searchValue={search}
                    onSearchChange={setSearch}
                    searchPlaceholder="Search products..."
                    filters={filters}
                    emptyMessage="No products found"
                />
                </div>
                <div id="footer" data-section="footer">
                <FooterSimple
                    columns={[
                        {"title":"Navigate","items":[{"label":"Home","href":"/"},{"label":"Services","href":"#services"},{"label":"Products","href":"#products"},{"label":"Results","href":"#results"}]},
                        {"title":"Resources","items":[{"label":"Blog","href":"/blog"},{"label":"FAQ","href":"#faq"},{"label":"Community","href":"#"},{"label":"Support","href":"#contact"}]},
                        {"title":"Legal","items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"Contact Us","href":"#contact"},{"label":"Disclaimer","href":"#"}]}
                    ]}
                    bottomLeftText="© 2025 Maxximize. All rights reserved."
                    bottomRightText="Transforming men, one result at a time"
                />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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