"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
import FooterLogoEmphasis from '@/components/sections/footer/FooterLogoEmphasis';
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="icon-arrow"
                defaultTextAnimation="entrance-slide"
                borderRadius="soft"
                contentWidth="compact"
                sizing="largeSmallSizeMediumTitles"
                background="aurora"
                cardStyle="soft-shadow"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="glass"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            brandName="Dashboard"
                            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">
                        <FooterLogoEmphasis
                            logoText="Dashboard"
                            columns={[
                                { items: [{ label: "Dashboard", href: "dashboard" }, { label: "Analytics", href: "analytics" }, { label: "Reports", href: "reports" }] },
                                { items: [{ label: "Settings", href: "settings" }, { label: "Preferences", href: "preferences" }, { label: "Profile", href: "profile" }] },
                                { items: [{ label: "Documentation", href: "docs" }, { label: "API Reference", href: "api" }, { label: "Support", href: "support" }] },
                                { items: [{ label: "Privacy Policy", href: "privacy" }, { label: "Terms of Service", href: "terms" }, { label: "Contact", href: "contact" }] }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="icon-arrow"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="compact"
            sizing="largeSmallSizeMediumTitles"
            background="aurora"
            cardStyle="soft-shadow"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="glass"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        brandName="Dashboard"
                        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">
                    <FooterLogoEmphasis
                        logoText="Dashboard"
                        columns={[
                            { items: [{ label: "Dashboard", href: "dashboard" }, { label: "Analytics", href: "analytics" }, { label: "Reports", href: "reports" }] },
                            { items: [{ label: "Settings", href: "settings" }, { label: "Preferences", href: "preferences" }, { label: "Profile", href: "profile" }] },
                            { items: [{ label: "Documentation", href: "docs" }, { label: "API Reference", href: "api" }, { label: "Support", href: "support" }] },
                            { items: [{ label: "Privacy Policy", href: "privacy" }, { label: "Terms of Service", href: "terms" }, { label: "Contact", href: "contact" }] }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}