"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterSimple from '@/components/sections/footer/FooterSimple';
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="entrance-slide"
                borderRadius="pill"
                contentWidth="mediumSmall"
                sizing="mediumLarge"
                background="floatingGradient"
                cardStyle="outline"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            brandName="MJ Cleaning"
                            bottomLeftText="Family-Owned & Insured"
                            bottomRightText="Same-Day Available"
                            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: "Services",                                    items: [
                                        { label: "Residential Deep Clean", href: "#services" },
                                        { label: "Move-Out/In Clean", href: "#services" },
                                        { label: "Post-Construction", href: "#services" },
                                        { label: "Commercial Cleaning", href: "#services" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About MJ", href: "#why-mj" },
                                        { label: "Testimonials", href: "#testimonials" },
                                        { label: "Book Now", href: "#booking" }
                                    ]
                                },
                                {
                                    title: "Contact",                                    items: [
                                        { label: "Phone: (555) 123-4567", href: "tel:+15551234567" },
                                        { label: "Email: hello@mjcleaning.com", href: "mailto:hello@mjcleaning.com" },
                                        { label: "FAQ", href: "#faq" }
                                    ]
                                },
                                {
                                    title: "Trust",                                    items: [
                                        { label: "Family-Owned" },
                                        { label: "Fully Insured" },
                                        { label: "Background-Checked" },
                                        { label: "5-Star Rated" }
                                    ]
                                }
                            ]}
                            bottomLeftText="© 2024 MJ Commercial & Residential Cleaning LLC. All rights reserved."
                            bottomRightText="Crafted with care by Jacy"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="directional-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="mediumSmall"
            sizing="mediumLarge"
            background="floatingGradient"
            cardStyle="outline"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        brandName="MJ Cleaning"
                        bottomLeftText="Family-Owned & Insured"
                        bottomRightText="Same-Day Available"
                        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: "Services",                                items: [
                                    { label: "Residential Deep Clean", href: "#services" },
                                    { label: "Move-Out/In Clean", href: "#services" },
                                    { label: "Post-Construction", href: "#services" },
                                    { label: "Commercial Cleaning", href: "#services" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About MJ", href: "#why-mj" },
                                    { label: "Testimonials", href: "#testimonials" },
                                    { label: "Book Now", href: "#booking" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "Phone: (555) 123-4567", href: "tel:+15551234567" },
                                    { label: "Email: hello@mjcleaning.com", href: "mailto:hello@mjcleaning.com" },
                                    { label: "FAQ", href: "#faq" }
                                ]
                            },
                            {
                                title: "Trust",                                items: [
                                    { label: "Family-Owned" },
                                    { label: "Fully Insured" },
                                    { label: "Background-Checked" },
                                    { label: "5-Star Rated" }
                                ]
                            }
                        ]}
                        bottomLeftText="© 2024 MJ Commercial & Residential Cleaning LLC. All rights reserved."
                        bottomRightText="Crafted with care by Jacy"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}