"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 FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
import { useProductCatalog } from "@/hooks/useProductCatalog";
import { useState } from "react";

export default function ShopPage() {
    const [cartOpen, setCartOpen] = useState(false);
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="icon-arrow"
                defaultTextAnimation="background-highlight"
                borderRadius="soft"
                contentWidth="mediumSmall"
                sizing="largeSmallSizeMediumTitles"
                background="aurora"
                cardStyle="glass-elevated"
                primaryButtonStyle="radial-glow"
                secondaryButtonStyle="solid"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="FitFlow"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                        />
                    </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">
                        <FooterBaseCard
                            logoText="FitFlow"
                            copyrightText="© 2025 FitFlow. All rights reserved. Transforming fitness journeys."
                            columns={[
                                {"title":"Product","items":[{"label":"Features","href":"#features"},{"label":"Pricing","href":"#pricing"},{"label":"Download","href":"#download"},{"label":"What's New","href":"#blog"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Careers","href":"#careers"},{"label":"Blog","href":"#blog"},{"label":"Press","href":"#press"}]},
                                {"title":"Resources","items":[{"label":"Help Center","href":"#faq"},{"label":"Community","href":"#community"},{"label":"Coaches","href":"#coaches"},{"label":"API Docs","href":"#api"}]},
                                {"title":"Legal","items":[{"label":"Privacy Policy","href":"#privacy"},{"label":"Terms of Service","href":"#terms"},{"label":"Cookie Policy","href":"#cookies"},{"label":"Contact","href":"#contact"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="icon-arrow"
            defaultTextAnimation="background-highlight"
            borderRadius="soft"
            contentWidth="mediumSmall"
            sizing="largeSmallSizeMediumTitles"
            background="aurora"
            cardStyle="glass-elevated"
            primaryButtonStyle="radial-glow"
            secondaryButtonStyle="solid"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="FitFlow"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </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">
                    <FooterBaseCard
                        logoText="FitFlow"
                        copyrightText="© 2025 FitFlow. All rights reserved. Transforming fitness journeys."
                        columns={[
                            {"title":"Product","items":[{"label":"Features","href":"#features"},{"label":"Pricing","href":"#pricing"},{"label":"Download","href":"#download"},{"label":"What's New","href":"#blog"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Careers","href":"#careers"},{"label":"Blog","href":"#blog"},{"label":"Press","href":"#press"}]},
                            {"title":"Resources","items":[{"label":"Help Center","href":"#faq"},{"label":"Community","href":"#community"},{"label":"Coaches","href":"#coaches"},{"label":"API Docs","href":"#api"}]},
                            {"title":"Legal","items":[{"label":"Privacy Policy","href":"#privacy"},{"label":"Terms of Service","href":"#terms"},{"label":"Cookie Policy","href":"#cookies"},{"label":"Contact","href":"#contact"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}