"use client";

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

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

    const [cartOpen, setCartOpen] = useState(false);

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="text-shift"
                defaultTextAnimation="background-highlight"
                borderRadius="pill"
                contentWidth="medium"
                sizing="largeSmall"
                background="floatingGradient"
                cardStyle="layered-gradient"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="solid"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            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">
                        <FooterBaseReveal
                            columns={[
                                {
                                    title: "Product",                                    items: [
                                        { label: "Features", href: "features" },
                                        { label: "Workouts", href: "workouts" },
                                        { label: "Pricing", href: "workouts" },
                                        { label: "Download", href: "contact" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "https://example.com/about" },
                                        { label: "Blog", href: "https://example.com/blog" },
                                        { label: "Careers", href: "https://example.com/careers" },
                                        { label: "Contact", href: "contact" }
                                    ]
                                },
                                {
                                    title: "Legal",                                    items: [
                                        { label: "Privacy Policy", href: "https://example.com/privacy" },
                                        { label: "Terms of Service", href: "https://example.com/terms" },
                                        { label: "Cookie Policy", href: "https://example.com/cookies" },
                                        { label: "Support", href: "contact" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 FitFlow. All rights reserved. Transform your fitness today."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="medium"
            sizing="largeSmall"
            background="floatingGradient"
            cardStyle="layered-gradient"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="solid"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="FitFlow"
                        navItems={[
                            { name: "Home", id: "/" },
                            { 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">
                    <FooterBaseReveal
                        columns={[
                            {
                                title: "Product",                                items: [
                                    { label: "Features", href: "features" },
                                    { label: "Workouts", href: "workouts" },
                                    { label: "Pricing", href: "workouts" },
                                    { label: "Download", href: "contact" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "https://example.com/about" },
                                    { label: "Blog", href: "https://example.com/blog" },
                                    { label: "Careers", href: "https://example.com/careers" },
                                    { label: "Contact", href: "contact" }
                                ]
                            },
                            {
                                title: "Legal",                                items: [
                                    { label: "Privacy Policy", href: "https://example.com/privacy" },
                                    { label: "Terms of Service", href: "https://example.com/terms" },
                                    { label: "Cookie Policy", href: "https://example.com/cookies" },
                                    { label: "Support", href: "contact" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 FitFlow. All rights reserved. Transform your fitness today."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}