"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
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 {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    const [cartOpen, setCartOpen] = useState(false);

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="expand-hover"
                defaultTextAnimation="background-highlight"
                borderRadius="rounded"
                contentWidth="small"
                sizing="largeSmallSizeLargeTitles"
                background="circleGradient"
                cardStyle="glass-depth"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="solid"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="StartupHub"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                            className="z-50"
                            navItemClassName="text-sm font-medium"
                            buttonClassName="px-6 py-2"
                        />
                    </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="StartupHub"
                            copyrightText="© 2025 StartupHub. All rights reserved."
                            columns={[
                                {
                                    title: "Product",                                    items: [
                                        { label: "Features", href: "about" },
                                        { label: "Pricing", href: "pricing" },
                                        { label: "Security", href: "#" },
                                        { label: "Roadmap", href: "#" }
                                    ]
                                },
                                {
                                    title: "Resources",                                    items: [
                                        { label: "Blog", href: "#" },
                                        { label: "Founder Toolkit", href: "#" },
                                        { label: "Investor Guide", href: "#" },
                                        { label: "Community", href: "#" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "about" },
                                        { label: "Careers", href: "#" },
                                        { label: "Contact", href: "contact" },
                                        { label: "Partners", href: "#" }
                                    ]
                                }
                            ]}
                            className="bg-opacity-50"
                            logoTextClassName="text-2xl font-light"
                            columnTitleClassName="font-medium text-base mb-4"
                            columnItemClassName="text-sm text-opacity-70 hover:text-opacity-100"
                            copyrightTextClassName="text-xs text-opacity-50"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="expand-hover"
            defaultTextAnimation="background-highlight"
            borderRadius="rounded"
            contentWidth="small"
            sizing="largeSmallSizeLargeTitles"
            background="circleGradient"
            cardStyle="glass-depth"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="solid"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="StartupHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" },
                            { name: "Contact", id: "contact" }
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                        className="z-50"
                        navItemClassName="text-sm font-medium"
                        buttonClassName="px-6 py-2"
                    />
                </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">
                    <FooterBase
                        logoText="StartupHub"
                        copyrightText="© 2025 StartupHub. All rights reserved."
                        columns={[
                            {
                                title: "Product",                                items: [
                                    { label: "Features", href: "about" },
                                    { label: "Pricing", href: "pricing" },
                                    { label: "Security", href: "#" },
                                    { label: "Roadmap", href: "#" }
                                ]
                            },
                            {
                                title: "Resources",                                items: [
                                    { label: "Blog", href: "#" },
                                    { label: "Founder Toolkit", href: "#" },
                                    { label: "Investor Guide", href: "#" },
                                    { label: "Community", href: "#" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "about" },
                                    { label: "Careers", href: "#" },
                                    { label: "Contact", href: "contact" },
                                    { label: "Partners", href: "#" }
                                ]
                            }
                        ]}
                        className="bg-opacity-50"
                        logoTextClassName="text-2xl font-light"
                        columnTitleClassName="font-medium text-base mb-4"
                        columnItemClassName="text-sm text-opacity-70 hover:text-opacity-100"
                        copyrightTextClassName="text-xs text-opacity-50"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}