"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 FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
import { useProductCatalog } from "@/hooks/useProductCatalog";

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="shift-hover"
                defaultTextAnimation="background-highlight"
                borderRadius="rounded"
                contentWidth="smallMedium"
                sizing="mediumLarge"
                background="grid"
                cardStyle="layered-gradient"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="glass"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="Superior Roofing & Exteriors"
                        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">
                    <FooterBaseCard
                        logoText="Superior Roofing"
                        columns={[
                            {
                                title: "Services",                                items: [
                                    { label: "Roof Replacement", href: "#services" },
                                    { label: "Gutter Services", href: "#services" },
                                    { label: "Siding Installation", href: "#services" },
                                    { label: "Roof Inspection", href: "#services" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "#about" },
                                    { label: "Reviews", href: "#testimonials" },
                                    { label: "Contact", href: "#contact" },
                                    { label: "Service Area", href: "#" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "Call: (630) 413-3999", href: "tel:(630)413-3999" },
                                    { label: "1620 Pebblewood Ln, Naperville, IL", href: "#" },
                                    { label: "Open 9 AM - 5 PM", href: "#" },
                                    { label: "Free Estimates", href: "#contact" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 Superior Roofing & Exteriors. All rights reserved."
                    />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="shift-hover"
            defaultTextAnimation="background-highlight"
            borderRadius="rounded"
            contentWidth="smallMedium"
            sizing="mediumLarge"
            background="grid"
            cardStyle="layered-gradient"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="glass"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                <NavbarStyleApple
                    brandName="Superior Roofing & Exteriors"
                    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">
                <FooterBaseCard
                    logoText="Superior Roofing"
                    columns={[
                        {
                            title: "Services",                            items: [
                                { label: "Roof Replacement", href: "#services" },
                                { label: "Gutter Services", href: "#services" },
                                { label: "Siding Installation", href: "#services" },
                                { label: "Roof Inspection", href: "#services" }
                            ]
                        },
                        {
                            title: "Company",                            items: [
                                { label: "About Us", href: "#about" },
                                { label: "Reviews", href: "#testimonials" },
                                { label: "Contact", href: "#contact" },
                                { label: "Service Area", href: "#" }
                            ]
                        },
                        {
                            title: "Contact",                            items: [
                                { label: "Call: (630) 413-3999", href: "tel:(630)413-3999" },
                                { label: "1620 Pebblewood Ln, Naperville, IL", href: "#" },
                                { label: "Open 9 AM - 5 PM", href: "#" },
                                { label: "Free Estimates", href: "#contact" }
                            ]
                        }
                    ]}
                    copyrightText="© 2025 Superior Roofing & Exteriors. All rights reserved."
                />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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