"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="text-stagger"
                defaultTextAnimation="entrance-slide"
                borderRadius="soft"
                contentWidth="mediumSmall"
                sizing="largeSmallSizeMediumTitles"
                background="noiseDiagonalGradient"
                cardStyle="gradient-bordered"
                primaryButtonStyle="primary-glow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="nav" data-section="nav">
                        <NavbarLayoutFloatingOverlay
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Features", id: "/#features" },
                                { name: "Products", id: "/#products" },
                                { name: "Testimonials", id: "/#testimonials" },
                                { name: "Contact", id: "/#contact" }
                            ]}
                            brandName="NoteGenius AI"
                            button={{ text: "Cart", onClick: () => {} }}
                        />
                    </div>
                    <div id="loading-products" data-section="loading-products">
                        <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://webuild-dev.s3.eu-north-1.amazonaws.com/users/user_32SzEkxKoNyIbQ4hnQYui6BHsfB/a-clean-modern-ai-notetaking-dashboard-i-1771701006792-1be35ae6.png?_wi=5"
                            imageAlt="NoteGenius AI Dashboard Footer"
                            columns={[
                                { title: "Product", items: [{ label: "Features", href: "/#features" }] },
                                { title: "Company", items: [] },
                                { title: "Resources", items: [{ label: "Blog", href: "/blog" }, { label: "Support", href: "/#faq" }] }
                            ]}
                            logoText="NoteGenius AI"
                            copyrightText="© 2024 NoteGenius AI. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="mediumSmall"
            sizing="largeSmallSizeMediumTitles"
            background="noiseDiagonalGradient"
            cardStyle="gradient-bordered"
            primaryButtonStyle="primary-glow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="nav" data-section="nav">
                    <NavbarLayoutFloatingOverlay
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Features", id: "/#features" },
                            { name: "Products", id: "/#products" },
                            { name: "Testimonials", id: "/#testimonials" },
                            { name: "Contact", id: "/#contact" }
                        ]}
                        brandName="NoteGenius AI"
                        button={{ text: "Cart", onClick: () => {} }}
                    />
                </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://webuild-dev.s3.eu-north-1.amazonaws.com/users/user_32SzEkxKoNyIbQ4hnQYui6BHsfB/a-clean-modern-ai-notetaking-dashboard-i-1771701006792-1be35ae6.png?_wi=6"
                        imageAlt="NoteGenius AI Dashboard Footer"
                        columns={[
                            { title: "Product", items: [{ label: "Features", href: "/#features" }] },
                            { title: "Company", items: [] },
                            { title: "Resources", items: [{ label: "Blog", href: "/blog" }, { label: "Support", href: "/#faq" }] }
                        ]}
                        logoText="NoteGenius AI"
                        copyrightText="© 2024 NoteGenius AI. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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