"use client";

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

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="shift-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="soft"
                contentWidth="medium"
                sizing="mediumLarge"
                background="noiseDiagonalGradient"
                cardStyle="layered-gradient"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="RBM's Attic Solutions"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Services", id: "services" },
                                { name: "Reviews", id: "testimonials" },
                                { name: "FAQ", id: "faq" },
                                { 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: "Attic Cleaning", href: "#services" },
                                        { label: "Attic Repair", href: "#services" },
                                        { label: "Insulation", href: "#services" },
                                        { label: "Roofing", href: "#services" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About", href: "#trust-section" },
                                        { label: "Contact", href: "#contact" },
                                        { label: "Reviews", href: "#testimonials" },
                                        { label: "FAQ", href: "#faq" }
                                    ]
                                },
                                {
                                    title: "Legal",                                    items: [
                                        { label: "Privacy Policy", href: "#" },
                                        { label: "Terms of Service", href: "#" },
                                        { label: "Contact Us", href: "#contact" }
                                    ]
                                }
                            ]}
                            bottomLeftText="© 2025 RBM's Attic Solutions, Insulation & Roofing. All rights reserved. Essex Junction, VT"
                            bottomRightText="Built for healthier, more comfortable homes."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="shift-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="medium"
            sizing="mediumLarge"
            background="noiseDiagonalGradient"
            cardStyle="layered-gradient"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="RBM's Attic Solutions"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Services", id: "services" },
                            { name: "Reviews", id: "testimonials" },
                            { name: "FAQ", id: "faq" },
                            { 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: "Attic Cleaning", href: "#services" },
                                    { label: "Attic Repair", href: "#services" },
                                    { label: "Insulation", href: "#services" },
                                    { label: "Roofing", href: "#services" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About", href: "#trust-section" },
                                    { label: "Contact", href: "#contact" },
                                    { label: "Reviews", href: "#testimonials" },
                                    { label: "FAQ", href: "#faq" }
                                ]
                            },
                            {
                                title: "Legal",                                items: [
                                    { label: "Privacy Policy", href: "#" },
                                    { label: "Terms of Service", href: "#" },
                                    { label: "Contact Us", href: "#contact" }
                                ]
                            }
                        ]}
                        bottomLeftText="© 2025 RBM's Attic Solutions, Insulation & Roofing. All rights reserved. Essex Junction, VT"
                        bottomRightText="Built for healthier, more comfortable homes."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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