"use client";

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

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

    const navItems = [{ "name": "Home", "id": "/" }, { "name": "Shop", "id": "/shop" }];
    const footerColumns = [
        { "title": "Vitality", "items": [{ "label": "About", "href": "/#about" }, { "label": "Innovations", "href": "/#features" }] },
        { "title": "Connect", "items": [{ "label": "Contact", "href": "/#contact" }, { "label": "FAQ", "href": "/#faq" }] },
        { "title": "Resources", "items": [{ "label": "Insights", "href": "/blog" }, { "label": "Press", "href": "#" }] }
    ];

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="hover-bubble"
                defaultTextAnimation="background-highlight"
                borderRadius="pill"
                contentWidth="mediumLarge"
                sizing="mediumLarge"
                background="grid"
                cardStyle="gradient-mesh"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="layered"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="nav" data-section="nav">
                        <NavbarStyleCentered
                            navItems={navItems}
                            brandName="Vitality"
                            button={{ text: "Cart", onClick: () => {} }}
                        />
                    </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>
                    <div id="footer" data-section="footer">
                        <FooterBaseReveal
                            columns={footerColumns}
                            copyrightText="© 2025 Vitality. All rights reserved."
                            className="bg-gray-800 text-white"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="mediumLarge"
            sizing="mediumLarge"
            background="grid"
            cardStyle="gradient-mesh"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="layered"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="nav" data-section="nav">
                    <NavbarStyleCentered
                        navItems={navItems}
                        brandName="Vitality"
                        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">
                    <FooterBaseReveal
                        columns={footerColumns}
                        copyrightText="© 2025 Vitality. All rights reserved."
                        className="bg-gray-800 text-white"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}
