"use client";

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

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

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="text-shift"
                defaultTextAnimation="background-highlight"
                borderRadius="soft"
                contentWidth="compact"
                sizing="largeSmallSizeLargeTitles"
                background="noiseDiagonalGradient"
                cardStyle="gradient-bordered"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="glass"
                headingFontWeight="normal"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="Montana Plumbing"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "About", id: "about" },
                                { name: "Services", id: "services" },
                                { name: "Work", id: "gallery" },
                                { name: "FAQ", id: "faq" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                            className="bg-opacity-95 backdrop-blur-md"
                            navItemClassName="font-medium text-sm tracking-wide"
                            buttonClassName="font-semibold px-6 py-2.5"
                        />
                    </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">
                        <FooterLogoReveal
                            logoText="Montana Plumbing"
                            leftLink={{ text: "Privacy Policy", href: "#" }}
                            rightLink={{ text: "License #12345", href: "#" }}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="background-highlight"
            borderRadius="soft"
            contentWidth="compact"
            sizing="largeSmallSizeLargeTitles"
            background="noiseDiagonalGradient"
            cardStyle="gradient-bordered"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="glass"
            headingFontWeight="normal"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="Montana Plumbing"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "About", id: "about" },
                            { name: "Services", id: "services" },
                            { name: "Work", id: "gallery" },
                            { name: "FAQ", id: "faq" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                        className="bg-opacity-95 backdrop-blur-md"
                        navItemClassName="font-medium text-sm tracking-wide"
                        buttonClassName="font-semibold px-6 py-2.5"
                    />
                </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">
                    <FooterLogoReveal
                        logoText="Montana Plumbing"
                        leftLink={{ text: "Privacy Policy", href: "#" }}
                        rightLink={{ text: "License #12345", href: "#" }}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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