"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 FooterMedia from '@/components/sections/footer/FooterMedia';
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="shift-hover"
                defaultTextAnimation="background-highlight"
                borderRadius="pill"
                contentWidth="small"
                sizing="largeSmall"
                background="grid"
                cardStyle="glass-elevated"
                primaryButtonStyle="radial-glow"
                secondaryButtonStyle="solid"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="nav" data-section="nav">
                        <NavbarStyleApple
                            brandName="Gladiatogo"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            button={{ text: "Cart", onClick: () => {} }}
                        />
                    </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="shift-hover"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="small"
            sizing="largeSmall"
            background="grid"
            cardStyle="glass-elevated"
            primaryButtonStyle="radial-glow"
            secondaryButtonStyle="solid"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="nav" data-section="nav">
                    <NavbarStyleApple
                        brandName="Gladiatogo"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        button={{ text: "Cart", onClick: () => {} }}
                    />
                </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>
                <div id="footer" data-section="footer">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/car-with-lights-driving-down-road_23-2151850179.jpg?_wi=3"
                        imageAlt="Road with cars at sunset"
                        logoText="Gladiatogo"
                        columns={[
                            { title: "Company", items: [{ label: "About Us", href: "/#about" }, { label: "Our Fleet", href: "/#product" }, { label: "Careers", href: "#" }] },
                            { title: "Support", items: [{ label: "FAQs", href: "/#faq" }, { label: "Contact", href: "/#contact" }, { label: "Help Center", href: "#" }] },
                            { title: "Legal", items: [{ label: "Privacy Policy", href: "#" }, { label: "Terms of Service", href: "#" }] }
                        ]}
                        copyrightText="© 2024 Gladiatogo. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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