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 ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import { useProductCatalog } from "@/hooks/useProductCatalog";
import FooterMedia from '@/components/sections/footer/FooterMedia';

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="shift-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="soft"
                contentWidth="mediumLarge"
                sizing="mediumLargeSizeMediumTitles"
                background="fluid"
                cardStyle="inset"
                primaryButtonStyle="primary-glow"
                secondaryButtonStyle="glass"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            brandName="Смачна Випічка"
                            button={{ text: "Cart", onClick: () => console.log("Cart functionality not available on this page") }}
                            className="py-4 px-6"
                            buttonClassName="px-5 py-2"
                            buttonTextClassName="font-medium"
                        />
                    </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/ripe-big-pumpkin-burlap_114579-29487.jpg"
                            imageAlt="Rustic fabric or dough texture as footer background."
                            logoText="Смачна Випічка"
                            columns={[
                                { title: "Menu", items: [{ label: "Breads", href: "#products" }, { label: "Pastries", href: "#products" }, { label: "Custom Cakes", href: "#contact" }] },
                                { title: "About Us", items: [{ label: "Our Story", href: "#about" }, { label: "Reviews", href: "#testimonials" }] },
                                { title: "Support", items: [{ label: "FAQ", href: "#faq" }, { label: "Contact", href: "#contact" }] }
                            ]}
                            copyrightText="© 2024 Смачна Випічка. All rights reserved."
                            mediaClassName="opacity-60"
                            className="text-foreground"
                            containerClassName="bg-card"
                            logoTextClassName="text-foreground"
                            columnTitleClassName="text-foreground"
                            columnItemClassName="text-foreground/80 hover:text-foreground"
                            copyrightTextClassName="text-foreground/60"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="shift-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="mediumLarge"
            sizing="mediumLargeSizeMediumTitles"
            background="fluid"
            cardStyle="inset"
            primaryButtonStyle="primary-glow"
            secondaryButtonStyle="glass"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        brandName="Смачна Випічка"
                        button={{ text: "Cart", onClick: () => console.log("Cart functionality not available on this page") }}
                        className="py-4 px-6"
                        buttonClassName="px-5 py-2"
                        buttonTextClassName="font-medium"
                    />
                </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/ripe-big-pumpkin-burlap_114579-29487.jpg"
                        imageAlt="Rustic fabric or dough texture as footer background."
                        logoText="Смачна Випічка"
                        columns={[
                            { title: "Menu", items: [{ label: "Breads", href: "#products" }, { label: "Pastries", href: "#products" }, { label: "Custom Cakes", href: "#contact" }] },
                            { title: "About Us", items: [{ label: "Our Story", href: "#about" }, { label: "Reviews", href: "#testimonials" }] },
                            { title: "Support", items: [{ label: "FAQ", href: "#faq" }, { label: "Contact", href: "#contact" }] }
                        ]}
                        copyrightText="© 2024 Смачна Випічка. All rights reserved."
                        mediaClassName="opacity-60"
                        className="text-foreground"
                        containerClassName="bg-card"
                        logoTextClassName="text-foreground"
                        columnTitleClassName="text-foreground"
                        columnItemClassName="text-foreground/80 hover:text-foreground"
                        copyrightTextClassName="text-foreground/60"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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