"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 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="elastic-effect"
                defaultTextAnimation="reveal-blur"
                borderRadius="soft"
                contentWidth="mediumLarge"
                sizing="largeSizeMediumTitles"
                background="floatingGradient"
                cardStyle="glass-elevated"
                primaryButtonStyle="flat"
                secondaryButtonStyle="solid"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="Martinez Roofing"
                            navItems={[
                                {name: "Home", id: "/"},
                                {name: "Metal Roofing", id: "services"},
                                {name: "Construction", id: "construction"},
                                {name: "Projects", id: "projects"},
                                {name: "Reviews", id: "reviews"},
                                {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: "Navigate",                                    items: [
                                        {label: "Home", href: "/"},
                                        {label: "Metal Roofing", href: "/metal-roofing"},
                                        {label: "Construction", href: "/construction"},
                                        {label: "Projects", href: "/projects"}
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        {label: "About Us", href: "/about"},
                                        {label: "Reviews", href: "#testimonials"},
                                        {label: "Contact", href: "/contact"}
                                    ]
                                },
                                {
                                    title: "Services",                                    items: [
                                        {label: "Standing Seam Install", href: "/metal-roofing"},
                                        {label: "Repairs & Replacement", href: "/metal-roofing"},
                                        {label: "Custom Projects", href: "/construction"}
                                    ]
                                },
                                {
                                    title: "Legal",                                    items: [
                                        {label: "Privacy Policy", href: "#"},
                                        {label: "Terms of Service", href: "#"}
                                    ]
                                }
                            ]}
                            bottomLeftText="© 2025 Martinez Metal Roofing & Construction. All rights reserved."
                            bottomRightText="Built for quality and precision."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="elastic-effect"
            defaultTextAnimation="reveal-blur"
            borderRadius="soft"
            contentWidth="mediumLarge"
            sizing="largeSizeMediumTitles"
            background="floatingGradient"
            cardStyle="glass-elevated"
            primaryButtonStyle="flat"
            secondaryButtonStyle="solid"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="Martinez Roofing"
                        navItems={[
                            {name: "Home", id: "/"},
                            {name: "Metal Roofing", id: "services"},
                            {name: "Construction", id: "construction"},
                            {name: "Projects", id: "projects"},
                            {name: "Reviews", id: "reviews"},
                            {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: "Navigate",                                items: [
                                    {label: "Home", href: "/"},
                                    {label: "Metal Roofing", href: "/metal-roofing"},
                                    {label: "Construction", href: "/construction"},
                                    {label: "Projects", href: "/projects"}
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    {label: "About Us", href: "/about"},
                                    {label: "Reviews", href: "#testimonials"},
                                    {label: "Contact", href: "/contact"}
                                ]
                            },
                            {
                                title: "Services",                                items: [
                                    {label: "Standing Seam Install", href: "/metal-roofing"},
                                    {label: "Repairs & Replacement", href: "/metal-roofing"},
                                    {label: "Custom Projects", href: "/construction"}
                                ]
                            },
                            {
                                title: "Legal",                                items: [
                                    {label: "Privacy Policy", href: "#"},
                                    {label: "Terms of Service", href: "#"}
                                ]
                            }
                        ]}
                        bottomLeftText="© 2025 Martinez Metal Roofing & Construction. All rights reserved."
                        bottomRightText="Built for quality and precision."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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