"use client";

import { Suspense } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
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="hover-bubble"
                defaultTextAnimation="reveal-blur"
                borderRadius="pill"
                contentWidth="smallMedium"
                sizing="large"
                background="noise"
                cardStyle="gradient-bordered"
                primaryButtonStyle="primary-glow"
                secondaryButtonStyle="layered"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="Sky Tree Services"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Services", id: "services" },
                                { name: "About", id: "about" },
                                { 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: "Services",                                    items: [
                                        { label: "Tree Removal", href: "/services#removal" },
                                        { label: "Emergency Services", href: "/services#emergency" },
                                        { label: "Tree Trimming", href: "/services#trimming" },
                                        { label: "Storm Cleanup", href: "/services#storm" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "/about" },
                                        { label: "Reviews", href: "#testimonials" },
                                        { label: "Contact", href: "/contact" },
                                        { label: "Service Area", href: "/services" }
                                    ]
                                },
                                {
                                    title: "Contact",                                    items: [
                                        { label: "📞 (615) 568-9651", href: "tel:+16155689651" },
                                        { label: "📍 3037 Runabout Dr, Nashville, TN 37217", href: "https://maps.google.com/?q=3037+Runabout+Dr+Nashville+TN+37217" },
                                        { label: "Open 24 Hours", href: "#" }
                                    ]
                                },
                                {
                                    title: "Legal",                                    items: [
                                        { label: "Privacy Policy", href: "#" },
                                        { label: "Terms of Service", href: "#" }
                                    ]
                                }
                            ]}
                            bottomLeftText="© 2025 Sky Tree Services LLC. All rights reserved."
                            bottomRightText="Professional Tree Service • Nashville, Tennessee"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="smallMedium"
            sizing="large"
            background="noise"
            cardStyle="gradient-bordered"
            primaryButtonStyle="primary-glow"
            secondaryButtonStyle="layered"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="Sky Tree Services"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Services", id: "services" },
                            { name: "About", id: "about" },
                            { 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: "Services",                                items: [
                                    { label: "Tree Removal", href: "/services#removal" },
                                    { label: "Emergency Services", href: "/services#emergency" },
                                    { label: "Tree Trimming", href: "/services#trimming" },
                                    { label: "Storm Cleanup", href: "/services#storm" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "/about" },
                                    { label: "Reviews", href: "#testimonials" },
                                    { label: "Contact", href: "/contact" },
                                    { label: "Service Area", href: "/services" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "📞 (615) 568-9651", href: "tel:+16155689651" },
                                    { label: "📍 3037 Runabout Dr, Nashville, TN 37217", href: "https://maps.google.com/?q=3037+Runabout+Dr+Nashville+TN+37217" },
                                    { label: "Open 24 Hours", href: "#" }
                                ]
                            },
                            {
                                title: "Legal",                                items: [
                                    { label: "Privacy Policy", href: "#" },
                                    { label: "Terms of Service", href: "#" }
                                ]
                            }
                        ]}
                        bottomLeftText="© 2025 Sky Tree Services LLC. All rights reserved."
                        bottomRightText="Professional Tree Service • Nashville, Tennessee"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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