"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
import FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
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="hover-bubble"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="mediumLarge"
                sizing="largeSmallSizeLargeTitles"
                background="circleGradient"
                cardStyle="soft-shadow"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="FitFlow"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Workouts","id":"workouts"},
                                {"name":"Plans","id":"plans"},
                                {"name":"Community","id":"testimonials"},
                                {"name":"FAQ","id":"faq"},
                                {"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"
                            columns={[
                                {"title":"Product","items":[{"label":"Features","href":"plans"},{"label":"Pricing","href":"contact"},{"label":"Security","href":"#"},{"label":"Blog","href":"#"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"#"},{"label":"Careers","href":"#"},{"label":"Press","href":"#"},{"label":"Contact","href":"contact"}]},
                                {"title":"Legal","items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"Cookie Policy","href":"#"},{"label":"GDPR","href":"#"}]},
                                {"title":"Follow","items":[{"label":"Twitter","href":"https://twitter.com"},{"label":"Instagram","href":"https://instagram.com"},{"label":"Facebook","href":"https://facebook.com"},{"label":"LinkedIn","href":"https://linkedin.com"}]}
                            ]
                            copyrightText="© 2025 FitFlow. All rights reserved. Transforming fitness, one rep at a time."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="mediumLarge"
            sizing="largeSmallSizeLargeTitles"
            background="circleGradient"
            cardStyle="soft-shadow"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="FitFlow"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Workouts","id":"workouts"},
                            {"name":"Plans","id":"plans"},
                            {"name":"Community","id":"testimonials"},
                            {"name":"FAQ","id":"faq"},
                            {"name":"Shop","id":"/shop"}
                        ]
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </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">
                    <FooterBaseCard
                        logoText="FitFlow"
                        columns={[
                            {"title":"Product","items":[{"label":"Features","href":"plans"},{"label":"Pricing","href":"contact"},{"label":"Security","href":"#"},{"label":"Blog","href":"#"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"#"},{"label":"Careers","href":"#"},{"label":"Press","href":"#"},{"label":"Contact","href":"contact"}]},
                            {"title":"Legal","items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"Cookie Policy","href":"#"},{"label":"GDPR","href":"#"}]},
                            {"title":"Follow","items":[{"label":"Twitter","href":"https://twitter.com"},{"label":"Instagram","href":"https://instagram.com"},{"label":"Facebook","href":"https://facebook.com"},{"label":"LinkedIn","href":"https://linkedin.com"}]}
                        ]
                        copyrightText="© 2025 FitFlow. All rights reserved. Transforming fitness, one rep at a time."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}