"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 FooterBaseReveal from '@/components/sections/footer/FooterBaseReveal';
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="directional-hover"
                defaultTextAnimation="background-highlight"
                borderRadius="sharp"
                contentWidth="smallMedium"
                sizing="largeSmallSizeMediumTitles"
                background="aurora"
                cardStyle="subtle-shadow"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="LaunchHub"
                            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: "Pricing", href: "https://example.com/pricing" },
                                        { label: "Security", href: "https://example.com/security" },
                                        { label: "Roadmap", href: "https://example.com/roadmap" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About", 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" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 LaunchHub. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="directional-hover"
            defaultTextAnimation="background-highlight"
            borderRadius="sharp"
            contentWidth="smallMedium"
            sizing="largeSmallSizeMediumTitles"
            background="aurora"
            cardStyle="subtle-shadow"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="LaunchHub"
                        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: "Pricing", href: "https://example.com/pricing" },
                                    { label: "Security", href: "https://example.com/security" },
                                    { label: "Roadmap", href: "https://example.com/roadmap" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About", 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" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 LaunchHub. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}