"use client";

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

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="largeSmall"
                background="noise"
                cardStyle="solid"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="glass"
                headingFontWeight="normal"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            navItems={[{ name: "Home", id: "/" }, { name: "Shop", id: "/shop" }]}
                            brandName="Dobry Khlib"
                            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-photo/white-cheese-bread-with-eggs_140725-3991.jpg"
                            imageAlt="Assortment of freshly baked Ukrainian goods"
                            columns={[
                                {title: "Bakery", items: [{label: "Our Story", href: "#about"}, {label: "Products", href: "#products"}, {label: "Order Online", href: "#products"}]},
                                {title: "Support", items: [{label: "FAQ", href: "#faq"}, {label: "Contact Us", href: "#contact"}]},
                                {title: "Legal", items: [{label: "Privacy Policy", href: "/privacy"}, {label: "Terms of Service", href: "/terms"}]}
                            ]}
                            logoText="Dobry Khlib"
                            copyrightText="© 2024 Dobry Khlib. All rights reserved."
                            onPrivacyClick={() => console.log('Privacy Policy clicked')}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="mediumSmall"
            sizing="largeSmall"
            background="noise"
            cardStyle="solid"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="glass"
            headingFontWeight="normal"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        navItems={[{ name: "Home", id: "/" }, { name: "Shop", id: "/shop" }]}
                        brandName="Dobry Khlib"
                        button={{ text: "Cart", onClick: () => console.log("cart") }}
                    />
                </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/white-cheese-bread-with-eggs_140725-3991.jpg"
                        imageAlt="Assortment of freshly baked Ukrainian goods"
                        columns={[
                            {title: "Bakery", items: [{label: "Our Story", href: "#about"}, {label: "Products", href: "#products"}, {label: "Order Online", href: "#products"}]},
                            {title: "Support", items: [{label: "FAQ", href: "#faq"}, {label: "Contact Us", href: "#contact"}]},
                            {title: "Legal", items: [{label: "Privacy Policy", href: "/privacy"}, {label: "Terms of Service", href: "/terms"}]}
                        ]}
                        logoText="Dobry Khlib"
                        copyrightText="© 2024 Dobry Khlib. All rights reserved."
                        onPrivacyClick={() => console.log('Privacy Policy clicked')}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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