"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";
import { useState } from "react";

export default function ShopPage() {
    const [cartOpen, setCartOpen] = useState(false);
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="hover-bubble"
                defaultTextAnimation="entrance-slide"
                borderRadius="sharp"
                contentWidth="mediumSmall"
                sizing="large"
                background="fluid"
                cardStyle="inset"
                primaryButtonStyle="flat"
                secondaryButtonStyle="glass"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="Luxe Haven"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"About","id":"about"},
                                {"name":"Rooms","id":"rooms"},
                                {"name":"Amenities","id":"amenities"},
                                {"name":"Pricing","id":"pricing"},
                                {"name":"Reviews","id":"testimonials"},
                                {"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">
                        <FooterMedia
                            imageSrc="https://img.b2bpic.net/free-photo/traveller-calling-hotel-concierge_482257-79728.jpg"
                            imageAlt="Luxe Haven Hotel Exterior"
                            logoText="Luxe Haven"
                            copyrightText="© 2025 Luxe Haven Hotels. All rights reserved."
                            columns={[
                                {"title":"Rooms","items":[{"label":"Deluxe Rooms","href":"#rooms"},{"label":"Premium Suites","href":"#rooms"},{"label":"Presidential Suite","href":"#rooms"},{"label":"Special Offers","href":"#pricing"}]},
                                {"title":"Services","items":[{"label":"Spa & Wellness","href":"#amenities"},{"label":"Fine Dining","href":"#amenities"},{"label":"Concierge","href":"#contact"},{"label":"Events & Meetings","href":"#contact"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Contact","href":"#contact"},{"label":"Careers","href":"#"},{"label":"Loyalty Program","href":"#"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="entrance-slide"
            borderRadius="sharp"
            contentWidth="mediumSmall"
            sizing="large"
            background="fluid"
            cardStyle="inset"
            primaryButtonStyle="flat"
            secondaryButtonStyle="glass"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="Luxe Haven"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"About","id":"about"},
                            {"name":"Rooms","id":"rooms"},
                            {"name":"Amenities","id":"amenities"},
                            {"name":"Pricing","id":"pricing"},
                            {"name":"Reviews","id":"testimonials"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/traveller-calling-hotel-concierge_482257-79728.jpg"
                        imageAlt="Luxe Haven Hotel Exterior"
                        logoText="Luxe Haven"
                        copyrightText="© 2025 Luxe Haven Hotels. All rights reserved."
                        columns={[
                            {"title":"Rooms","items":[{"label":"Deluxe Rooms","href":"#rooms"},{"label":"Premium Suites","href":"#rooms"},{"label":"Presidential Suite","href":"#rooms"},{"label":"Special Offers","href":"#pricing"}]},
                            {"title":"Services","items":[{"label":"Spa & Wellness","href":"#amenities"},{"label":"Fine Dining","href":"#amenities"},{"label":"Concierge","href":"#contact"},{"label":"Events & Meetings","href":"#contact"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Contact","href":"#contact"},{"label":"Careers","href":"#"},{"label":"Loyalty Program","href":"#"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}
