"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 FooterBase from '@/components/sections/footer/FooterBase';
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="directional-hover"
                defaultTextAnimation="reveal-blur"
                borderRadius="soft"
                contentWidth="smallMedium"
                sizing="mediumLarge"
                background="blurBottom"
                cardStyle="gradient-mesh"
                primaryButtonStyle="shadow"
                secondaryButtonStyle="layered"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="Elite Track"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "About", id: "about" },
                                { name: "Features", id: "features" },
                                { name: "Programs", id: "programs" },
                                { name: "FAQ", id: "faq" },
                                { name: "Contact", id: "contact" },
                                { 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">
                        <FooterBase
                            logoText="Elite Track"
                            copyrightText="© 2025 Elite Track Indoor Facility. All rights reserved."
                            columns={[
                                {
                                    title: "Programs",                                    items: [
                                        { label: "Youth Development", href: "#programs" },
                                        { label: "Competitive Teams", href: "#programs" },
                                        { label: "Elite Coaching", href: "#programs" },
                                        { label: "Community Fitness", href: "#programs" }
                                    ]
                                },
                                {
                                    title: "About",                                    items: [
                                        { label: "Our Facility", href: "#about" },
                                        { label: "Track Features", href: "#features" },
                                        { label: "Coaching Staff", href: "#features" },
                                        { label: "Book a Tour", href: "#contact" }
                                    ]
                                },
                                {
                                    title: "Support",                                    items: [
                                        { label: "FAQ", href: "#faq" },
                                        { label: "Contact Us", href: "#contact" },
                                        { label: "Privacy Policy", href: "https://example.com/privacy" },
                                        { label: "Terms of Service", href: "https://example.com/terms" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="directional-hover"
            defaultTextAnimation="reveal-blur"
            borderRadius="soft"
            contentWidth="smallMedium"
            sizing="mediumLarge"
            background="blurBottom"
            cardStyle="gradient-mesh"
            primaryButtonStyle="shadow"
            secondaryButtonStyle="layered"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="Elite Track"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "About", id: "about" },
                            { name: "Features", id: "features" },
                            { name: "Programs", id: "programs" },
                            { name: "FAQ", id: "faq" },
                            { name: "Contact", id: "contact" },
                            { 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">
                    <FooterBase
                        logoText="Elite Track"
                        copyrightText="© 2025 Elite Track Indoor Facility. All rights reserved."
                        columns={[
                            {
                                title: "Programs",                                items: [
                                    { label: "Youth Development", href: "#programs" },
                                    { label: "Competitive Teams", href: "#programs" },
                                    { label: "Elite Coaching", href: "#programs" },
                                    { label: "Community Fitness", href: "#programs" }
                                ]
                            },
                            {
                                title: "About",                                items: [
                                    { label: "Our Facility", href: "#about" },
                                    { label: "Track Features", href: "#features" },
                                    { label: "Coaching Staff", href: "#features" },
                                    { label: "Book a Tour", href: "#contact" }
                                ]
                            },
                            {
                                title: "Support",                                items: [
                                    { label: "FAQ", href: "#faq" },
                                    { label: "Contact Us", href: "#contact" },
                                    { label: "Privacy Policy", href: "https://example.com/privacy" },
                                    { label: "Terms of Service", href: "https://example.com/terms" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}