"use client";

import { Suspense } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
import FooterLogoEmphasis from '@/components/sections/footer/FooterLogoEmphasis';
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="hover-bubble"
                defaultTextAnimation="reveal-blur"
                borderRadius="rounded"
                contentWidth="compact"
                sizing="mediumSizeLargeTitles"
                background="blurBottom"
                cardStyle="outline"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="glass"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="UrbanStyle"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"products"},
                                {"name":"About","id":"about"},
                                {"name":"Pricing","id":"pricing"}
                            ]}
                            button={{"text":"Contact Us","href":"contact"}}
                        />
                    </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">
                        <FooterLogoEmphasis
                            logoText="UrbanStyle"
                            columns={[
                                {"items":[{"label":"Home","href":"#home"},{"label":"Shop","href":"#products"},{"label":"About","href":"#about"},{"label":"Pricing","href":"#pricing"}]},
                                {"items":[{"label":"Contact Us","href":"#contact"},{"label":"FAQ","href":"#"},{"label":"Shipping Info","href":"#"},{"label":"Returns","href":"#"}]},
                                {"items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"Accessibility","href":"#"},{"label":"Sustainability","href":"#"}]},
                                {"items":[{"label":"Instagram","href":"https://instagram.com"},{"label":"Twitter","href":"https://twitter.com"},{"label":"Facebook","href":"https://facebook.com"},{"label":"TikTok","href":"https://tiktok.com"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="reveal-blur"
            borderRadius="rounded"
            contentWidth="compact"
            sizing="mediumSizeLargeTitles"
            background="blurBottom"
            cardStyle="outline"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="glass"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="UrbanStyle"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"products"},
                            {"name":"About","id":"about"},
                            {"name":"Pricing","id":"pricing"}
                        ]}
                        button={{"text":"Contact Us","href":"contact"}}
                    />
                </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">
                    <FooterLogoEmphasis
                        logoText="UrbanStyle"
                        columns={[
                            {"items":[{"label":"Home","href":"#home"},{"label":"Shop","href":"#products"},{"label":"About","href":"#about"},{"label":"Pricing","href":"#pricing"}]},
                            {"items":[{"label":"Contact Us","href":"#contact"},{"label":"FAQ","href":"#"},{"label":"Shipping Info","href":"#"},{"label":"Returns","href":"#"}]},
                            {"items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"Accessibility","href":"#"},{"label":"Sustainability","href":"#"}]},
                            {"items":[{"label":"Instagram","href":"https://instagram.com"},{"label":"Twitter","href":"https://twitter.com"},{"label":"Facebook","href":"https://facebook.com"},{"label":"TikTok","href":"https://tiktok.com"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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