"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
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="reveal-blur"
                borderRadius="pill"
                contentWidth="smallMedium"
                sizing="largeSmallSizeMediumTitles"
                background="circleGradient"
                cardStyle="outline"
                primaryButtonStyle="radial-glow"
                secondaryButtonStyle="solid"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="ShopHub"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "products" },
                                { name: "About", id: "about" },
                                { name: "Reviews", id: "testimonials" },
                                { name: "Contact", id: "contact" }
                            ]}
                            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: "Products",                                    items: [
                                        { label: "Sneakers", href: "products" },
                                        { label: "Running Shoes", href: "products" },
                                        { label: "Training Gear", href: "products" },
                                        { label: "Sale Items", href: "products" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "about" },
                                        { label: "Our Team", href: "about" },
                                        { label: "Careers", href: "#" },
                                        { label: "Blog", href: "#" }
                                    ]
                                },
                                {
                                    title: "Support",                                    items: [
                                        { label: "Contact Us", href: "contact" },
                                        { label: "Shipping Info", href: "#" },
                                        { label: "Returns", href: "#" },
                                        { label: "FAQs", href: "faq" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 ShopHub | All Rights Reserved"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="smallMedium"
            sizing="largeSmallSizeMediumTitles"
            background="circleGradient"
            cardStyle="outline"
            primaryButtonStyle="radial-glow"
            secondaryButtonStyle="solid"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="ShopHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "products" },
                            { name: "About", id: "about" },
                            { name: "Reviews", id: "testimonials" },
                            { name: "Contact", id: "contact" }
                        ]}
                        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">
                    <FooterBaseReveal
                        columns={[
                            {
                                title: "Products",                                items: [
                                    { label: "Sneakers", href: "products" },
                                    { label: "Running Shoes", href: "products" },
                                    { label: "Training Gear", href: "products" },
                                    { label: "Sale Items", href: "products" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "about" },
                                    { label: "Our Team", href: "about" },
                                    { label: "Careers", href: "#" },
                                    { label: "Blog", href: "#" }
                                ]
                            },
                            {
                                title: "Support",                                items: [
                                    { label: "Contact Us", href: "contact" },
                                    { label: "Shipping Info", href: "#" },
                                    { label: "Returns", href: "#" },
                                    { label: "FAQs", href: "faq" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 ShopHub | All Rights Reserved"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}