"use client";

import { Suspense } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from "@/components/navbar/NavbarLayoutFloatingInline";
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" });

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="icon-arrow"
                defaultTextAnimation="background-highlight"
                borderRadius="pill"
                contentWidth="mediumLarge"
                sizing="largeSmall"
                background="none"
                cardStyle="soft-shadow"
                primaryButtonStyle="radial-glow"
                secondaryButtonStyle="layered"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Menu", id: "features" },
                                { name: "About", id: "about" },
                                { name: "Locations", id: "contact" },
                                { name: "Blog", id: "/blog" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            brandName="Brew Haven"
                            button={{ text: "Cart", onClick: () => console.log("cart") }}
                        />
                    </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
                            logoText="Brew Haven"
                            copyrightText="© 2025 | Brew Haven Coffee Co."
                            columns={[
                                {
                                    title: "Menu",                                    items: [
                                        { label: "Coffee", href: "#features" },
                                        { label: "Pastries", href: "#features" },
                                        { label: "Shop Beans", href: "#product" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "#about" },
                                        { label: "Locations", href: "#contact" },
                                        { label: "Careers", href: "#" }
                                    ]
                                },
                                {
                                    title: "Connect",                                    items: [
                                        { label: "Instagram", href: "https://instagram.com" },
                                        { label: "Contact", href: "#contact" },
                                        { label: "Newsletter", href: "#" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="icon-arrow"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="mediumLarge"
            sizing="largeSmall"
            background="none"
            cardStyle="soft-shadow"
            primaryButtonStyle="radial-glow"
            secondaryButtonStyle="layered"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Menu", id: "features" },
                            { name: "About", id: "about" },
                            { name: "Locations", id: "contact" },
                            { name: "Blog", id: "/blog" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        brandName="Brew Haven"
                        button={{ text: "Cart", onClick: () => console.log("cart") }}
                    />
                </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">
                    <FooterBase
                        logoText="Brew Haven"
                        copyrightText="© 2025 | Brew Haven Coffee Co."
                        columns={[
                            {
                                title: "Menu",                                items: [
                                    { label: "Coffee", href: "#features" },
                                    { label: "Pastries", href: "#features" },
                                    { label: "Shop Beans", href: "#product" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "#about" },
                                    { label: "Locations", href: "#contact" },
                                    { label: "Careers", href: "#" }
                                ]
                            },
                            {
                                title: "Connect",                                items: [
                                    { label: "Instagram", href: "https://instagram.com" },
                                    { label: "Contact", href: "#contact" },
                                    { label: "Newsletter", href: "#" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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