"use client";

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

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="expand-hover"
                defaultTextAnimation="background-highlight"
                borderRadius="pill"
                contentWidth="small"
                sizing="mediumSizeLargeTitles"
                background="aurora"
                cardStyle="subtle-shadow"
                primaryButtonStyle="shadow"
                secondaryButtonStyle="solid"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="The Grand Hotel"
                            navItems={[{ name: "Home", id: "/" }, { name: "Shop", id: "/shop" }]}
                            button={{ text: "Cart", onClick: () => {} }} // Non-functional cart button as state is not available here
                            className="py-4 px-6 md:px-12"
                            buttonClassName="px-5 py-2"
                            buttonTextClassName="font-semibold"
                        />
                    </div>
                    <div id="loading-state" data-section="loading-state">
                        <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">
                        <FooterMedia
                            imageSrc="https://img.b2bpic.net/free-photo/wooden-sauna-with-mountain-view-panoramic-calm_169016-70823.jpg"
                            imageAlt="Luxurious hotel lobby with elegant decor"
                            columns={[
                                { "title": "Hotel", "items": [{ "label": "About Us", "href": "#about" }, { "label": "Our Rooms", "href": "#rooms" }, { "label": "Amenities", "href": "#amenities" }] },
                                { "title": "Guest Services", "items": [{ "label": "Concierge", "href": "#" }, { "label": "Dining", "href": "#" }, { "label": "Spa", "href": "#" }] },
                                { "title": "Legal", "items": [{ "label": "Privacy Policy", "href": "/privacy" }, { "label": "Terms of Service", "href": "/terms" }] }
                            ]}
                            logoText="The Grand Hotel"
                            copyrightText="© 2024 The Grand Hotel. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="expand-hover"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="small"
            sizing="mediumSizeLargeTitles"
            background="aurora"
            cardStyle="subtle-shadow"
            primaryButtonStyle="shadow"
            secondaryButtonStyle="solid"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="The Grand Hotel"
                        navItems={[{ name: "Home", id: "/" }, { name: "Shop", id: "/shop" }]}
                        button={{ text: "Cart", onClick: () => {} }} // Non-functional cart button as state is not available here
                        className="py-4 px-6 md:px-12"
                        buttonClassName="px-5 py-2"
                        buttonTextClassName="font-semibold"
                    />
                </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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/wooden-sauna-with-mountain-view-panoramic-calm_169016-70823.jpg"
                        imageAlt="Luxurious hotel lobby with elegant decor"
                        columns={[
                            { "title": "Hotel", "items": [{ "label": "About Us", "href": "#about" }, { "label": "Our Rooms", "href": "#rooms" }, { "label": "Amenities", "href": "#amenities" }] },
                            { "title": "Guest Services", "items": [{ "label": "Concierge", "href": "#" }, { "label": "Dining", "href": "#" }, { "label": "Spa", "href": "#" }] },
                            { "title": "Legal", "items": [{ "label": "Privacy Policy", "href": "/privacy" }, { "label": "Terms of Service", "href": "/terms" }] }
                        ]}
                        logoText="The Grand Hotel"
                        copyrightText="© 2024 The Grand Hotel. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}
