"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 FooterBaseReveal from '@/components/sections/footer/FooterBaseReveal';
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-magnetic"
                defaultTextAnimation="background-highlight"
                borderRadius="pill"
                contentWidth="mediumSmall"
                sizing="mediumSizeLargeTitles"
                background="fluid"
                cardStyle="solid"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="solid"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="Sky Tree Services"
                        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">
                    <FooterBaseReveal
                        columns={[
                            {
                                title: "Services",                                items: [
                                    { label: "Tree Removal", href: "#services" },
                                    { label: "Emergency Services", href: "#services" },
                                    { label: "Tree Trimming", href: "#services" },
                                    { label: "Storm Cleanup", href: "#services" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "/about" },
                                    { label: "Reviews", href: "/reviews" },
                                    { label: "Contact", href: "/contact" },
                                    { label: "Service Areas", href: "#" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "📞 (615) 568-9651", href: "tel:+16155689651" },
                                    { label: "Open 24 Hours", href: "#" },
                                    { label: "3037 Runabout Dr, Nashville, TN 37217", href: "#" },
                                    { label: "Emergency Service Available", href: "#" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 Sky Tree Services LLC. All rights reserved. Licensed & Insured."
                    />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-magnetic"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="mediumSmall"
            sizing="mediumSizeLargeTitles"
            background="fluid"
            cardStyle="solid"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="solid"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                <NavbarLayoutFloatingOverlay
                    brandName="Sky Tree Services"
                    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">
                <FooterBaseReveal
                    columns={[
                        {
                            title: "Services",                            items: [
                                { label: "Tree Removal", href: "#services" },
                                { label: "Emergency Services", href: "#services" },
                                { label: "Tree Trimming", href: "#services" },
                                { label: "Storm Cleanup", href: "#services" }
                            ]
                        },
                        {
                            title: "Company",                            items: [
                                { label: "About Us", href: "/about" },
                                { label: "Reviews", href: "/reviews" },
                                { label: "Contact", href: "/contact" },
                                { label: "Service Areas", href: "#" }
                            ]
                        },
                        {
                            title: "Contact",                            items: [
                                { label: "📞 (615) 568-9651", href: "tel:+16155689651" },
                                { label: "Open 24 Hours", href: "#" },
                                { label: "3037 Runabout Dr, Nashville, TN 37217", href: "#" },
                                { label: "Emergency Service Available", href: "#" }
                            ]
                        }
                    ]}
                    copyrightText="© 2025 Sky Tree Services LLC. All rights reserved. Licensed & Insured."
                />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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