"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";

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="bounce-effect"
                defaultTextAnimation="background-highlight"
                borderRadius="soft"
                contentWidth="mediumLarge"
                sizing="mediumLargeSizeMediumTitles"
                background="blurBottom"
                cardStyle="inset"
                primaryButtonStyle="flat"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="Heating & Cooling Chicago"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Services","id":"services"},
                                {"name":"About","id":"about"},
                                {"name":"Why Us","id":"why-us"},
                                {"name":"Testimonials","id":"testimonials"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            button={{"text":"Cart","onClick":() => console.log("cart")}}
                            className="bg-white/80 backdrop-blur-sm border border-accent shadow-lg"
                        />
                    </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="Heating & Cooling Chicago"
                            leftLink={{"text":"Privacy Policy","href":"#"}}
                            rightLink={{"text":"Terms of Service","href":"#"}}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="bounce-effect"
            defaultTextAnimation="background-highlight"
            borderRadius="soft"
            contentWidth="mediumLarge"
            sizing="mediumLargeSizeMediumTitles"
            background="blurBottom"
            cardStyle="inset"
            primaryButtonStyle="flat"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="Heating & Cooling Chicago"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Services","id":"services"},
                            {"name":"About","id":"about"},
                            {"name":"Why Us","id":"why-us"},
                            {"name":"Testimonials","id":"testimonials"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        button={{"text":"Cart","onClick":() => console.log("cart")}}
                        className="bg-white/80 backdrop-blur-sm border border-accent shadow-lg"
                    />
                </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">
                    <FooterLogoReveal
                        logoText="Heating & Cooling Chicago"
                        leftLink={{"text":"Privacy Policy","href":"#"}}
                        rightLink={{"text":"Terms of Service","href":"#"}}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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