"use client";

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

export default function ShopPage() {
    const [cartOpen, setCartOpen] = useState(false);
    
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="shift-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="compact"
                sizing="mediumLargeSizeMediumTitles"
                background="floatingGradient"
                cardStyle="outline"
                primaryButtonStyle="shadow"
                secondaryButtonStyle="layered"
                headingFontWeight="normal"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"About","id":"about"},
                                {"name":"Portfolio","id":"portfolio"},
                                {"name":"Team","id":"team"},
                                {"name":"Contact","id":"contact"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            brandName="CapitalVenture"
                            button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                        />
                    </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">
                        <FooterBase
                            logoText="CapitalVenture"
                            copyrightText="© 2025 CapitalVenture Partners. All rights reserved."
                            columns={[
                                {"title":"Company","items":[{"label":"Home","href":"/"},{"label":"About Us","href":"/about"},{"label":"Our Portfolio","href":"/portfolio"},{"label":"Contact","href":"/contact"}]},
                                {"title":"Resources","items":[{"label":"Investment Process","href":"#"},{"label":"Market Insights","href":"#"},{"label":"News & Updates","href":"#"},{"label":"Careers","href":"#"}]},
                                {"title":"Legal","items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"SEC Disclosures","href":"#"},{"label":"Contact Us","href":"#contact"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="shift-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="compact"
            sizing="mediumLargeSizeMediumTitles"
            background="floatingGradient"
            cardStyle="outline"
            primaryButtonStyle="shadow"
            secondaryButtonStyle="layered"
            headingFontWeight="normal"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"About","id":"about"},
                            {"name":"Portfolio","id":"portfolio"},
                            {"name":"Team","id":"team"},
                            {"name":"Contact","id":"contact"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        brandName="CapitalVenture"
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </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">
                    <FooterBase
                        logoText="CapitalVenture"
                        copyrightText="© 2025 CapitalVenture Partners. All rights reserved."
                        columns={[
                            {"title":"Company","items":[{"label":"Home","href":"/"},{"label":"About Us","href":"/about"},{"label":"Our Portfolio","href":"/portfolio"},{"label":"Contact","href":"/contact"}]},
                            {"title":"Resources","items":[{"label":"Investment Process","href":"#"},{"label":"Market Insights","href":"#"},{"label":"News & Updates","href":"#"},{"label":"Careers","href":"#"}]},
                            {"title":"Legal","items":[{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"SEC Disclosures","href":"#"},{"label":"Contact Us","href":"#contact"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}