"use client";

import { Suspense } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
import FooterMedia from '@/components/sections/footer/FooterMedia';
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="icon-arrow"
                defaultTextAnimation="background-highlight"
                borderRadius="rounded"
                contentWidth="compact"
                sizing="largeSmall"
                background="floatingGradient"
                cardStyle="glass-elevated"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="layered"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="Wanderlust"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            button={{ text: "Cart", onClick: () => console.log("cart") }}
                        />
                    </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-vector/earth-map-dotted_1284-34073.jpg"
                            imageAlt="World map background"
                            logoText="Wanderlust"
                            copyrightText="© 2025 Wanderlust Travel Agency. All rights reserved."
                            columns={[
                                {"title":"Services","items":[{"label":"Custom Tours","href":"#services"},{"label":"Group Travel","href":"#"},{"label":"Adventure Packages","href":"#"}]},
                                {"title":"Company","items":[{"label":"Our Team","href":"#"},{"label":"Blog","href":"#"}]},
                                {"title":"Support","items":[{"label":"FAQ","href":"#faq"},{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="icon-arrow"
            defaultTextAnimation="background-highlight"
            borderRadius="rounded"
            contentWidth="compact"
            sizing="largeSmall"
            background="floatingGradient"
            cardStyle="glass-elevated"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="layered"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="Wanderlust"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        button={{ text: "Cart", onClick: () => console.log("cart") }}
                    />
                </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-vector/earth-map-dotted_1284-34073.jpg"
                        imageAlt="World map background"
                        logoText="Wanderlust"
                        copyrightText="© 2025 Wanderlust Travel Agency. All rights reserved."
                        columns={[
                            {"title":"Services","items":[{"label":"Custom Tours","href":"#services"},{"label":"Group Travel","href":"#"},{"label":"Adventure Packages","href":"#"}]},
                            {"title":"Company","items":[{"label":"Our Team","href":"#"},{"label":"Blog","href":"#"}]},
                            {"title":"Support","items":[{"label":"FAQ","href":"#faq"},{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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