"use client";

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

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="elastic-effect"
                defaultTextAnimation="reveal-blur"
                borderRadius="rounded"
                contentWidth="mediumSmall"
                sizing="mediumLarge"
                background="noiseDiagonalGradient"
                cardStyle="outline"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="layered"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            navItems={[{ name: "Home", id: "/" }, { name: "Shop", id: "/shop" }]}
                            brandName="The Grand Hotel"
                            bottomLeftText="Your Luxurious Escape"
                            bottomRightText="reservations@grandhotel.com"
                            topBarClassName="h-20"
                            button={{ text: "Cart", onClick: () => {} }}
                        />
                    </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>
                    <div id="footer" data-section="footer">
                        <FooterSimple
                            columns={[
                                {"title":"Explore","items":[{"label":"Rooms & Suites","href":"#rooms"},{"label":"Amenities","href":"#features"},{"label":"Gallery","href":"#hero"}]},
                                {"title":"Services","items":[{"label":"Dining","href":"#hero"},{"label":"Spa","href":"#features"},{"label":"Events"}]},
                                {"title":"About","items":[{"label":"Our Story","href":"#about"},{"label":"Careers"},{"label":"Press"}]},
                                {"title":"Legal","items":[{"label":"Privacy Policy"},{"label":"Terms of Service"}]}
                            ]}
                            bottomLeftText="© 2024 The Grand Hotel. All rights reserved."
                            bottomRightText="Crafted with Distinction"
                            ariaLabel="Site footer"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="elastic-effect"
            defaultTextAnimation="reveal-blur"
            borderRadius="rounded"
            contentWidth="mediumSmall"
            sizing="mediumLarge"
            background="noiseDiagonalGradient"
            cardStyle="outline"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="layered"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[{ name: "Home", id: "/" }, { name: "Shop", id: "/shop" }]}
                        brandName="The Grand Hotel"
                        bottomLeftText="Your Luxurious Escape"
                        bottomRightText="reservations@grandhotel.com"
                        topBarClassName="h-20"
                        button={{ text: "Cart", onClick: () => {} }}
                    />
                </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">
                    <FooterSimple
                        columns={[
                            {"title":"Explore","items":[{"label":"Rooms & Suites","href":"#rooms"},{"label":"Amenities","href":"#features"},{"label":"Gallery","href":"#hero"}]},
                            {"title":"Services","items":[{"label":"Dining","href":"#hero"},{"label":"Spa","href":"#features"},{"label":"Events"}]},
                            {"title":"About","items":[{"label":"Our Story","href":"#about"},{"label":"Careers"},{"label":"Press"}]},
                            {"title":"Legal","items":[{"label":"Privacy Policy"},{"label":"Terms of Service"}]}
                        ]}
                        bottomLeftText="© 2024 The Grand Hotel. All rights reserved."
                        bottomRightText="Crafted with Distinction"
                        ariaLabel="Site footer"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

export default function ShopPage() {
    return (
        <Suspense>
            <ShopPageContent />
        </Suspense>
    );
}
