"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleApple from '@/components/navbar/NavbarStyleApple/NavbarStyleApple';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
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="elastic-effect"
                defaultTextAnimation="background-highlight"
                borderRadius="sharp"
                contentWidth="smallMedium"
                sizing="largeSizeMediumTitles"
                background="floatingGradient"
                cardStyle="layered-gradient"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="glass"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="StartupHub"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" },
                                { name: "Contact", id: "/contacts" }
                            ]}
                            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">
                        <FooterBaseCard
                            logoText="StartupHub"
                            columns={[
                                {
                                    title: "Product",                                    items: [
                                        { label: "Features", href: "#features" },
                                        { label: "Pricing", href: "#pricing" },
                                        { label: "Portfolio", href: "https://example.com/portfolio" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About", href: "#about" },
                                        { label: "Team", href: "#team" },
                                        { label: "Blog", href: "https://example.com/blog" }
                                    ]
                                },
                                {
                                    title: "Resources",                                    items: [
                                        { label: "Founders Guide", href: "https://example.com/guide" },
                                        { label: "Documentation", href: "https://example.com/docs" },
                                        { label: "Community", href: "https://example.com/community" }
                                    ]
                                },
                                {
                                    title: "Legal",                                    items: [
                                        { label: "Privacy Policy", href: "https://example.com/privacy" },
                                        { label: "Terms of Service", href: "https://example.com/terms" },
                                        { label: "Contact", href: "/contacts" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 StartupHub. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="elastic-effect"
            defaultTextAnimation="background-highlight"
            borderRadius="sharp"
            contentWidth="smallMedium"
            sizing="largeSizeMediumTitles"
            background="floatingGradient"
            cardStyle="layered-gradient"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="glass"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="StartupHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" },
                            { name: "Contact", id: "/contacts" }
                        ]}
                        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">
                    <FooterBaseCard
                        logoText="StartupHub"
                        columns={[
                            {
                                title: "Product",                                items: [
                                    { label: "Features", href: "#features" },
                                    { label: "Pricing", href: "#pricing" },
                                    { label: "Portfolio", href: "https://example.com/portfolio" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About", href: "#about" },
                                    { label: "Team", href: "#team" },
                                    { label: "Blog", href: "https://example.com/blog" }
                                ]
                            },
                            {
                                title: "Resources",                                items: [
                                    { label: "Founders Guide", href: "https://example.com/guide" },
                                    { label: "Documentation", href: "https://example.com/docs" },
                                    { label: "Community", href: "https://example.com/community" }
                                ]
                            },
                            {
                                title: "Legal",                                items: [
                                    { label: "Privacy Policy", href: "https://example.com/privacy" },
                                    { label: "Terms of Service", href: "https://example.com/terms" },
                                    { label: "Contact", href: "/contacts" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 StartupHub. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}