"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingOverlay from '@/components/navbar/NavbarLayoutFloatingOverlay/NavbarLayoutFloatingOverlay';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterLogoEmphasis from '@/components/sections/footer/FooterLogoEmphasis';
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="hover-bubble"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="mediumSmall"
                sizing="mediumLargeSizeMediumTitles"
                background="circleGradient"
                cardStyle="solid"
                primaryButtonStyle="flat"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="Mobile One"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Services","id":"services"},
                                {"name":"Why Us","id":"about"},
                                {"name":"Pricing","id":"pricing"},
                                {"name":"Testimonials","id":"testimonials"},
                                {"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">
                        <FooterLogoEmphasis
                            logoText="Mobile One Detailing"
                            columns={[
                                {"items":[{"label":"Services","href":"services"},{"label":"Pricing","href":"pricing"},{"label":"About","href":"about"}]},
                                {"items":[{"label":"Testimonials","href":"testimonials"},{"label":"FAQ","href":"faq"},{"label":"Contact","href":"contact"}]},
                                {"items":[{"label":"Service Area","href":"#"},{"label":"Book Now","href":"#contact"},{"label":"Mobile App","href":"#"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="mediumSmall"
            sizing="mediumLargeSizeMediumTitles"
            background="circleGradient"
            cardStyle="solid"
            primaryButtonStyle="flat"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="Mobile One"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Services","id":"services"},
                            {"name":"Why Us","id":"about"},
                            {"name":"Pricing","id":"pricing"},
                            {"name":"Testimonials","id":"testimonials"},
                            {"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">
                    <FooterLogoEmphasis
                        logoText="Mobile One Detailing"
                        columns={[
                            {"items":[{"label":"Services","href":"services"},{"label":"Pricing","href":"pricing"},{"label":"About","href":"about"}]},
                            {"items":[{"label":"Testimonials","href":"testimonials"},{"label":"FAQ","href":"faq"},{"label":"Contact","href":"contact"}]},
                            {"items":[{"label":"Service Area","href":"#"},{"label":"Book Now","href":"#contact"},{"label":"Mobile App","href":"#"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}