"use client";

import { Suspense } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleApple from '@/components/navbar/NavbarStyleApple/NavbarStyleApple';
import FooterBase from '@/components/sections/footer/FooterBase';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import { useProductCatalog } from "@/hooks/useProductCatalog";

function ShopPageContent() {
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    const navItems = [
        { name: "Home", id: "/" },
        { name: "About", id: "/#about" },
        { name: "Shop", id: "/shop" },
        { name: "Blog", id: "/blog" },
        { name: "Testimonials", id: "/#testimonials" },
        { name: "Contact", id: "/#contact" },
    ];

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="expand-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="medium"
                sizing="mediumLarge"
                background="floatingGradient"
                cardStyle="solid"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="layered"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="nav" data-section="nav">
                        <NavbarStyleApple
                            brandName="Olla"
                            navItems={navItems}
                            button={{ text: "Cart", onClick: () => {} }}
                        />
                    </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
                            columns={[
                                { title: "Shop", items: [{ label: "Bouquets", href: "/shop#bouquets" }, { label: "Plants", href: "/shop#plants" }, { label: "Occasions", href: "/shop#occasions" }] },
                                { title: "Company", items: [{ label: "About Us", href: "/about" }, { label: "Services", href: "/services" }, { label: "FAQ", href: "/faq" }] },
                                { title: "Connect", items: [{ label: "Contact", href: "/contact" }, { label: "Instagram", href: "https://www.instagram.com/ollastudio" }] }
                            ]}
                            logoText="Olla"
                            copyrightText="© 2024 Olla Flowers Studio. All rights reserved."
                            ariaLabel="Site footer"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="expand-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="medium"
            sizing="mediumLarge"
            background="floatingGradient"
            cardStyle="solid"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="layered"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="nav" data-section="nav">
                    <NavbarStyleApple
                        brandName="Olla"
                        navItems={navItems}
                        button={{ text: "Cart", onClick: () => {} }}
                    />
                </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">
                    <FooterBase
                        columns={[
                            { title: "Shop", items: [{ label: "Bouquets", href: "/shop#bouquets" }, { label: "Plants", href: "/shop#plants" }, { label: "Occasions", href: "/shop#occasions" }] },
                            { title: "Company", items: [{ label: "About Us", href: "/about" }, { label: "Services", href: "/services" }, { label: "FAQ", href: "/faq" }] },
                            { title: "Connect", items: [{ label: "Contact", href: "/contact" }, { label: "Instagram", href: "https://www.instagram.com/ollastudio" }] }
                        ]}
                        logoText="Olla"
                        copyrightText="© 2024 Olla Flowers Studio. All rights reserved."
                        ariaLabel="Site footer"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

export default function ShopPage() {
    return (
        <Suspense>
            <ShopPageContent />
        </Suspense>
    );
}
