"use client";

import { Suspense } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingOverlay from '@/components/navbar/NavbarLayoutFloatingOverlay/NavbarLayoutFloatingOverlay';
import FooterSimple from '@/components/sections/footer/FooterSimple';
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="directional-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="smallMedium"
                sizing="largeSmallSizeMediumTitles"
                background="circleGradient"
                cardStyle="glass-depth"
                primaryButtonStyle="primary-glow"
                secondaryButtonStyle="glass"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="TN Lawn Care Pros"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Services", id: "services" },
                            { name: "Why Us", id: "why-us" },
                            { name: "Reviews", id: "testimonials" },
                            { name: "Contact", id: "contact" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        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">
                    <FooterSimple
                        columns={[
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "#why-us" },
                                    { label: "Services", href: "#services" },
                                    { label: "Reviews", href: "#testimonials" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "Call Now", href: "tel:(615)992-0482" },
                                    { label: "Get Quote", href: "#contact" },
                                    { label: "Hours: Open - Closes 8:30 PM", href: "#" }
                                ]
                            },
                            {
                                title: "Service Area",                                items: [
                                    { label: "Nashville", href: "#" },
                                    { label: "Memphis", href: "#" },
                                    { label: "Knoxville", href: "#" }
                                ]
                            }
                        ]}
                        bottomLeftText="© 2025 TN Lawn Care Pros. All rights reserved."
                        bottomRightText="Serving Tennessee with pride"
                    />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="directional-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="smallMedium"
            sizing="largeSmallSizeMediumTitles"
            background="circleGradient"
            cardStyle="glass-depth"
            primaryButtonStyle="primary-glow"
            secondaryButtonStyle="glass"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                <NavbarLayoutFloatingOverlay
                    brandName="TN Lawn Care Pros"
                    navItems={[
                        { name: "Home", id: "/" },
                        { name: "Services", id: "services" },
                        { name: "Why Us", id: "why-us" },
                        { name: "Reviews", id: "testimonials" },
                        { name: "Contact", id: "contact" },
                        { name: "Shop", id: "/shop" }
                    ]}
                    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">
                <FooterSimple
                    columns={[
                        {
                            title: "Company",                            items: [
                                { label: "About Us", href: "#why-us" },
                                { label: "Services", href: "#services" },
                                { label: "Reviews", href: "#testimonials" }
                            ]
                        },
                        {
                            title: "Contact",                            items: [
                                { label: "Call Now", href: "tel:(615)992-0482" },
                                { label: "Get Quote", href: "#contact" },
                                { label: "Hours: Open - Closes 8:30 PM", href: "#" }
                            ]
                        },
                        {
                            title: "Service Area",                            items: [
                                { label: "Nashville", href: "#" },
                                { label: "Memphis", href: "#" },
                                { label: "Knoxville", href: "#" }
                            ]
                        }
                    ]}
                    bottomLeftText="© 2025 TN Lawn Care Pros. All rights reserved."
                    bottomRightText="Serving Tennessee with pride"
                />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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