"use client";

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

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

    const {
        isOpen: cartOpen,
        setIsOpen: setCartOpen,
    } = useCart();

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="shift-hover"
                defaultTextAnimation="reveal-blur"
                borderRadius="pill"
                contentWidth="smallMedium"
                sizing="medium"
                background="floatingGradient"
                cardStyle="inset"
                primaryButtonStyle="primary-glow"
                secondaryButtonStyle="solid"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            brandName="Wanderlust Escapes"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Destinations","id":"destinations"},
                                {"name":"About","id":"about"},
                                {"name":"Experiences","id":"experiences"},
                                {"name":"Testimonials","id":"testimonials"},
                                {"name":"Contact","id":"contact"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            bottomLeftText="Luxury Travel Since 2010"
                            bottomRightText="hello@wanderlustescapes.com"
                            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/maldives-island_1203-7338.jpg"
                            imageAlt="Luxury travel experience footer"
                            logoText="Wanderlust Escapes"
                            copyrightText="© 2025 Wanderlust Escapes. All rights reserved."
                            columns={[
                                {"title":"Destinations","items":[{"label":"Asia","href":"destinations"},{"label":"Europe","href":"destinations"},{"label":"Americas","href":"destinations"},{"label":"Africa","href":"destinations"}]},
                                {"title":"Services","items":[{"label":"Custom Itineraries","href":"experiences"},{"label":"Luxury Packages","href":"experiences"},{"label":"Concierge Service","href":"about"},{"label":"Group Travel","href":"contact"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"about"},{"label":"Contact","href":"contact"},{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="shift-hover"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="smallMedium"
            sizing="medium"
            background="floatingGradient"
            cardStyle="inset"
            primaryButtonStyle="primary-glow"
            secondaryButtonStyle="solid"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        brandName="Wanderlust Escapes"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Destinations","id":"destinations"},
                            {"name":"About","id":"about"},
                            {"name":"Experiences","id":"experiences"},
                            {"name":"Testimonials","id":"testimonials"},
                            {"name":"Contact","id":"contact"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        bottomLeftText="Luxury Travel Since 2010"
                        bottomRightText="hello@wanderlustescapes.com"
                        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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/maldives-island_1203-7338.jpg"
                        imageAlt="Luxury travel experience footer"
                        logoText="Wanderlust Escapes"
                        copyrightText="© 2025 Wanderlust Escapes. All rights reserved."
                        columns={[
                            {"title":"Destinations","items":[{"label":"Asia","href":"destinations"},{"label":"Europe","href":"destinations"},{"label":"Americas","href":"destinations"},{"label":"Africa","href":"destinations"}]},
                            {"title":"Services","items":[{"label":"Custom Itineraries","href":"experiences"},{"label":"Luxury Packages","href":"experiences"},{"label":"Concierge Service","href":"about"},{"label":"Group Travel","href":"contact"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"about"},{"label":"Contact","href":"contact"},{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}