"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleApple from '@/components/navbar/NavbarStyleApple/NavbarStyleApple';
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 {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="directional-hover"
                defaultTextAnimation="background-highlight"
                borderRadius="pill"
                contentWidth="mediumLarge"
                sizing="largeSmall"
                background="aurora"
                cardStyle="outline"
                primaryButtonStyle="flat"
                secondaryButtonStyle="glass"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="ShopHub"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Products", id: "products" },
                                { name: "Reviews", id: "reviews" },
                                { name: "Contact", id: "contact" },
                                { name: "Support", 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">
                        <FooterBaseReveal
                            columns={[
                                {
                                    title: "Product",                                    items: [
                                        { label: "Running Shoes", href: "products" },
                                        { label: "Related Items", href: "related-products" },
                                        { label: "New Releases", href: "https://example.com/new" },
                                        { label: "Sizing Guide", href: "faq" }
                                    ]
                                },
                                {
                                    title: "Support",                                    items: [
                                        { label: "Contact Us", href: "contact" },
                                        { label: "FAQ", href: "faq" },
                                        { label: "Shipping Info", href: "https://example.com/shipping" },
                                        { label: "Returns", href: "https://example.com/returns" }
                                    ]
                                },
                                {
                                    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: "Sustainability", href: "https://example.com/sustainability" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 ShopHub Premium Runners. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="directional-hover"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="mediumLarge"
            sizing="largeSmall"
            background="aurora"
            cardStyle="outline"
            primaryButtonStyle="flat"
            secondaryButtonStyle="glass"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="ShopHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Products", id: "products" },
                            { name: "Reviews", id: "reviews" },
                            { name: "Contact", id: "contact" },
                            { name: "Support", 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">
                    <FooterBaseReveal
                        columns={[
                            {
                                title: "Product",                                items: [
                                    { label: "Running Shoes", href: "products" },
                                    { label: "Related Items", href: "related-products" },
                                    { label: "New Releases", href: "https://example.com/new" },
                                    { label: "Sizing Guide", href: "faq" }
                                ]
                            },
                            {
                                title: "Support",                                items: [
                                    { label: "Contact Us", href: "contact" },
                                    { label: "FAQ", href: "faq" },
                                    { label: "Shipping Info", href: "https://example.com/shipping" },
                                    { label: "Returns", href: "https://example.com/returns" }
                                ]
                            },
                            {
                                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: "Sustainability", href: "https://example.com/sustainability" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 ShopHub Premium Runners. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}