"use client";

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

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

    const [cartOpen, setCartOpen] = useState(false);

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="directional-hover"
                defaultTextAnimation="background-highlight"
                borderRadius="soft"
                contentWidth="smallMedium"
                sizing="mediumLargeSizeMediumTitles"
                background="circleGradient"
                cardStyle="layered-gradient"
                primaryButtonStyle="primary-glow"
                secondaryButtonStyle="glass"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="Catamount"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                        />
                    </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: "Contact",                                    items: [
                                        { label: "Phone: (802) 473-2606", href: "tel:+18024732606" },
                                        { label: "1774 Baptist St, Williamstown, VT 05679", href: "https://maps.google.com/?q=1774+Baptist+St,+Williamstown,+VT+05679" },
                                        { label: "Open 24/7", href: "#" }
                                    ]
                                },
                                {
                                    title: "Services",                                    items: [
                                        { label: "Tree Removal", href: "#services" },
                                        { label: "Tree Trimming", href: "#services" },
                                        { label: "Emergency Service", href: "#services" }
                                    ]
                                },
                                {
                                    title: "About",                                    items: [
                                        { label: "Our Team", href: "#team" },
                                        { label: "Reviews", href: "#testimonials" },
                                        { label: "Service Area", href: "#" }
                                    ]
                                }
                            ]}
                            bottomLeftText="© 2025 Catamount Tree Service. All rights reserved. Serving Williamstown, VT."
                            bottomRightText="Professional Tree Care | 24/7 Emergency Service"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="directional-hover"
            defaultTextAnimation="background-highlight"
            borderRadius="soft"
            contentWidth="smallMedium"
            sizing="mediumLargeSizeMediumTitles"
            background="circleGradient"
            cardStyle="layered-gradient"
            primaryButtonStyle="primary-glow"
            secondaryButtonStyle="glass"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="Catamount"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </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: "Contact",                                items: [
                                    { label: "Phone: (802) 473-2606", href: "tel:+18024732606" },
                                    { label: "1774 Baptist St, Williamstown, VT 05679", href: "https://maps.google.com/?q=1774+Baptist+St,+Williamstown,+VT+05679" },
                                    { label: "Open 24/7", href: "#" }
                                ]
                            },
                            {
                                title: "Services",                                items: [
                                    { label: "Tree Removal", href: "#services" },
                                    { label: "Tree Trimming", href: "#services" },
                                    { label: "Emergency Service", href: "#services" }
                                ]
                            },
                            {
                                title: "About",                                items: [
                                    { label: "Our Team", href: "#team" },
                                    { label: "Reviews", href: "#testimonials" },
                                    { label: "Service Area", href: "#" }
                                ]
                            }
                        ]}
                        bottomLeftText="© 2025 Catamount Tree Service. All rights reserved. Serving Williamstown, VT."
                        bottomRightText="Professional Tree Care | 24/7 Emergency Service"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}