"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="text-shift"
                defaultTextAnimation="entrance-slide"
                borderRadius="sharp"
                contentWidth="smallMedium"
                sizing="mediumSizeLargeTitles"
                background="none"
                cardStyle="solid"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="Dashboard"
                            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: "overview" },
                                        { label: "Analytics", href: "analytics" },
                                        { label: "Reports", href: "reports" }
                                    ]
                                },
                                {
                                    title: "Support",                                    items: [
                                        { label: "Documentation", href: "https://example.com/docs" },
                                        { label: "Help Center", href: "https://example.com/help" },
                                        { label: "Contact Us", href: "settings" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About", href: "https://example.com/about" },
                                        { label: "Blog", href: "https://example.com/blog" },
                                        { label: "Careers", href: "https://example.com/careers" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 Dashboard Analytics | All rights reserved"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="entrance-slide"
            borderRadius="sharp"
            contentWidth="smallMedium"
            sizing="mediumSizeLargeTitles"
            background="none"
            cardStyle="solid"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="Dashboard"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        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: "Product",                                items: [
                                    { label: "Features", href: "overview" },
                                    { label: "Analytics", href: "analytics" },
                                    { label: "Reports", href: "reports" }
                                ]
                            },
                            {
                                title: "Support",                                items: [
                                    { label: "Documentation", href: "https://example.com/docs" },
                                    { label: "Help Center", href: "https://example.com/help" },
                                    { label: "Contact Us", href: "settings" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About", href: "https://example.com/about" },
                                    { label: "Blog", href: "https://example.com/blog" },
                                    { label: "Careers", href: "https://example.com/careers" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 Dashboard Analytics | All rights reserved"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}