"use client";

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

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

    const { setIsOpen: setCartOpen } = useCart();

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="expand-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="soft"
                contentWidth="mediumLarge"
                sizing="mediumLarge"
                background="none"
                cardStyle="subtle-shadow"
                primaryButtonStyle="shadow"
                secondaryButtonStyle="glass"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Rooms", id: "rooms" },
                                { name: "Amenities", id: "amenities" },
                                { name: "Offers", id: "offers" },
                                { name: "About Us", id: "about" },
                                { name: "Contact", id: "contact" },
                                { name: "Shop", id: "/shop" },
                            ]}
                            brandName="Grandeur Hotel"
                            button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                        />
                    </div>
                    <div id="loading-section" data-section="loading-section">
                        <main className="min-h-screen flex items-center justify-center pt-20">
                            <p className="text-foreground">Loading products...</p>
                        </main>
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="expand-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="mediumLarge"
            sizing="mediumLarge"
            background="none"
            cardStyle="subtle-shadow"
            primaryButtonStyle="shadow"
            secondaryButtonStyle="glass"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Rooms", id: "rooms" },
                            { name: "Amenities", id: "amenities" },
                            { name: "Offers", id: "offers" },
                            { name: "About Us", id: "about" },
                            { name: "Contact", id: "contact" },
                            { name: "Shop", id: "/shop" },
                        ]}
                        brandName="Grandeur Hotel"
                        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>
            </ReactLenis>
        </ThemeProvider>
    );
}
