"use client";

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

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="icon-arrow"
                defaultTextAnimation="reveal-blur"
                borderRadius="pill"
                contentWidth="smallMedium"
                sizing="large"
                background="noise"
                cardStyle="gradient-radial"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="glass"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="D2B Marketing"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Services","id":"features"},
                            {"name":"Results","id":"about"},
                            {"name":"Pricing","id":"pricing"},
                            {"name":"Contact","id":"contact"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        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">
                        <FooterBaseCard
                            logoText="D2B Marketing"
                            columns={[
                                {"title":"Services","items":[{"label":"SEO Optimization","href":"#features"},{"label":"Social Media Marketing","href":"#features"},{"label":"PPC Advertising","href":"#features"},{"label":"Content Marketing","href":"#features"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Our Results","href":"#about"},{"label":"Pricing","href":"#pricing"},{"label":"Contact","href":"#contact"}]},
                                {"title":"Resources","items":[{"label":"Blog","href":"#"},{"label":"Case Studies","href":"#"},{"label":"Free Tools","href":"#"},{"label":"FAQ","href":"#faq"}]},
                                {"title":"Legal","items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"Cookie Policy","href":"#"}]}
                            ]}
                            copyrightText="© 2025 D2B Marketing. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="icon-arrow"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="smallMedium"
            sizing="large"
            background="noise"
            cardStyle="gradient-radial"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="glass"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                <NavbarLayoutFloatingInline
                    brandName="D2B Marketing"
                    navItems={[
                        {"name":"Home","id":"/"},
                        {"name":"Services","id":"features"},
                        {"name":"Results","id":"about"},
                        {"name":"Pricing","id":"pricing"},
                        {"name":"Contact","id":"contact"},
                        {"name":"Shop","id":"/shop"}
                    ]}
                    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">
                    <FooterBaseCard
                        logoText="D2B Marketing"
                        columns={[
                            {"title":"Services","items":[{"label":"SEO Optimization","href":"#features"},{"label":"Social Media Marketing","href":"#features"},{"label":"PPC Advertising","href":"#features"},{"label":"Content Marketing","href":"#features"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Our Results","href":"#about"},{"label":"Pricing","href":"#pricing"},{"label":"Contact","href":"#contact"}]},
                            {"title":"Resources","items":[{"label":"Blog","href":"#"},{"label":"Case Studies","href":"#"},{"label":"Free Tools","href":"#"},{"label":"FAQ","href":"#faq"}]},
                            {"title":"Legal","items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"Cookie Policy","href":"#"}]}
                        ]}
                        copyrightText="© 2025 D2B Marketing. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}