"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
import FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
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="text-stagger"
                defaultTextAnimation="reveal-blur"
                borderRadius="rounded"
                contentWidth="medium"
                sizing="mediumSizeLargeTitles"
                background="none"
                cardStyle="outline"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="solid"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="Catamount"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Services", id: "services" },
                                { name: "Reviews", id: "testimonials" },
                                { name: "About", id: "team" },
                                { name: "FAQ", id: "faq" },
                                { 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">
                        <FooterBaseCard
                            logoText="Catamount Tree Service"
                            columns={[
                                {
                                    title: "Quick Links",                                    items: [
                                        { label: "Services", href: "#services" },
                                        { label: "Reviews", href: "#testimonials" },
                                        { label: "Team", href: "#team" },
                                        { label: "FAQ", href: "#faq" }
                                    ]
                                },
                                {
                                    title: "Contact",                                    items: [
                                        { label: "Call: (802) 473-2606", href: "tel:(802)-473-2606" },
                                        { label: "Email: info@catamounttrees.com", href: "mailto:info@catamounttrees.com" },
                                        { label: "Address: 1774 Baptist St, Williamstown, VT 05679", href: "https://maps.google.com/?q=1774+Baptist+St+Williamstown+VT+05679" },
                                        { label: "24/7 Emergency Service", href: "tel:(802)-473-2606" }
                                    ]
                                },
                                {
                                    title: "Service Areas",                                    items: [
                                        { label: "Williamstown, VT", href: "#" },
                                        { label: "Emergency Response", href: "#" },
                                        { label: "Free Estimates", href: "#contact" },
                                        { label: "Licensed & Insured", href: "#" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 Catamount Tree Service. All rights reserved. Licensed & Insured."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="reveal-blur"
            borderRadius="rounded"
            contentWidth="medium"
            sizing="mediumSizeLargeTitles"
            background="none"
            cardStyle="outline"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="solid"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="Catamount"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Services", id: "services" },
                            { name: "Reviews", id: "testimonials" },
                            { name: "About", id: "team" },
                            { name: "FAQ", id: "faq" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </div>
                <div id="product-catalog" data-section="product-catalog">
                    <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="Catamount Tree Service"
                        columns={[
                            {
                                title: "Quick Links",                                items: [
                                    { label: "Services", href: "#services" },
                                    { label: "Reviews", href: "#testimonials" },
                                    { label: "Team", href: "#team" },
                                    { label: "FAQ", href: "#faq" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "Call: (802) 473-2606", href: "tel:(802)-473-2606" },
                                    { label: "Email: info@catamounttrees.com", href: "mailto:info@catamounttrees.com" },
                                    { label: "Address: 1774 Baptist St, Williamstown, VT 05679", href: "https://maps.google.com/?q=1774+Baptist+St+Williamstown+VT+05679" },
                                    { label: "24/7 Emergency Service", href: "tel:(802)-473-2606" }
                                ]
                            },
                            {
                                title: "Service Areas",                                items: [
                                    { label: "Williamstown, VT", href: "#" },
                                    { label: "Emergency Response", href: "#" },
                                    { label: "Free Estimates", href: "#contact" },
                                    { label: "Licensed & Insured", href: "#" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 Catamount Tree Service. All rights reserved. Licensed & Insured."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}