"use client";

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

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="expand-hover"
                defaultTextAnimation="reveal-blur"
                borderRadius="soft"
                contentWidth="compact"
                sizing="largeSmallSizeLargeTitles"
                background="grid"
                cardStyle="outline"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="layered"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="The Soap Shop"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"products"},
                                {"name":"About","id":"about"},
                                {"name":"Reviews","id":"testimonials"},
                                {"name":"FAQ","id":"faq"},
                                {"name":"Contact","id":"contact"}
                            ]}
                            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="http://img.b2bpic.net/free-photo/clean-bathroom-minimal-home-decor_53876-134402.jpg?_wi=3"
                            imageAlt="Footer background"
                            logoText="The Soap Shop"
                            copyrightText="© 2025 The Soap Shop. Handcrafted organic soap bars."
                            columns={[
                                {"title":"Shop","items":[{"label":"All Products","href":"#products"},{"label":"Best Sellers","href":"#products"},{"label":"Bundles","href":"#products"},{"label":"Gift Sets","href":"#products"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Ingredients","href":"#about"},{"label":"Our Story","href":"#about"},{"label":"Contact","href":"#contact"}]},
                                {"title":"Legal","items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms & Conditions","href":"#"},{"label":"Shipping Info","href":"#"},{"label":"Returns","href":"#"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="expand-hover"
            defaultTextAnimation="reveal-blur"
            borderRadius="soft"
            contentWidth="compact"
            sizing="largeSmallSizeLargeTitles"
            background="grid"
            cardStyle="outline"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="layered"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="The Soap Shop"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"products"},
                            {"name":"About","id":"about"},
                            {"name":"Reviews","id":"testimonials"},
                            {"name":"FAQ","id":"faq"},
                            {"name":"Contact","id":"contact"}
                        ]}
                        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="http://img.b2bpic.net/free-photo/clean-bathroom-minimal-home-decor_53876-134402.jpg?_wi=4"
                        imageAlt="Footer background"
                        logoText="The Soap Shop"
                        copyrightText="© 2025 The Soap Shop. Handcrafted organic soap bars."
                        columns={[
                            {"title":"Shop","items":[{"label":"All Products","href":"#products"},{"label":"Best Sellers","href":"#products"},{"label":"Bundles","href":"#products"},{"label":"Gift Sets","href":"#products"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Ingredients","href":"#about"},{"label":"Our Story","href":"#about"},{"label":"Contact","href":"#contact"}]},
                            {"title":"Legal","items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms & Conditions","href":"#"},{"label":"Shipping Info","href":"#"},{"label":"Returns","href":"#"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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