"use client";

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

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="expand-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="mediumLarge"
                sizing="mediumLargeSizeMediumTitles"
                background="fluid"
                cardStyle="glass-elevated"
                primaryButtonStyle="radial-glow"
                secondaryButtonStyle="solid"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="Catamount Tree Service"
                            navItems={[
                                { name: "Home", id: "/" },
                                { 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>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="expand-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="mediumLarge"
            sizing="mediumLargeSizeMediumTitles"
            background="fluid"
            cardStyle="glass-elevated"
            primaryButtonStyle="radial-glow"
            secondaryButtonStyle="solid"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="Catamount Tree Service"
                        navItems={[
                            { name: "Home", id: "/" },
                            { 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: "tree-removal" },
                                    { label: "Tree Trimming", href: "tree-trimming" },
                                    { label: "Emergency Service", href: "emergency-service" },
                                    { label: "Storm Cleanup", href: "tree-removal" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "about" },
                                    { label: "Reviews", href: "reviews" },
                                    { label: "Service Area", href: "services" },
                                    { label: "Contact", href: "contact" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "📞 (802) 473-2606", href: "tel:(802)4732606" },
                                    { label: "1774 Baptist St, Williamstown, VT 05679", href: "https://maps.google.com/?q=1774+Baptist+St+Williamstown+VT+05679" },
                                    { label: "Available 24/7", href: "contact" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 Catamount Tree Service. All rights reserved. | Serving Central Vermont"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}