"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 FooterBase from '@/components/sections/footer/FooterBase';
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="icon-arrow"
                defaultTextAnimation="entrance-slide"
                borderRadius="soft"
                contentWidth="mediumSmall"
                sizing="mediumLargeSizeMediumTitles"
                background="floatingGradient"
                cardStyle="solid"
                primaryButtonStyle="radial-glow"
                secondaryButtonStyle="solid"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="SaaS Pro"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            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="SaaS Pro"
                            copyrightText="© 2025 SaaS Pro. All rights reserved."
                            columns={[
                                {
                                    title: "Product",                                    items: [
                                        { label: "Features", href: "features" },
                                        { label: "Pricing", href: "pricing" },
                                        { label: "Security", href: "https://example.com/security" },
                                        { label: "Roadmap", href: "https://example.com/roadmap" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About", href: "https://example.com/about" },
                                        { label: "Blog", href: "https://example.com/blog" },
                                        { label: "Careers", href: "https://example.com/careers" },
                                        { label: "Contact", href: "contact" }
                                    ]
                                },
                                {
                                    title: "Resources",                                    items: [
                                        { label: "Documentation", href: "https://docs.example.com" },
                                        { label: "API Reference", href: "https://api.example.com" },
                                        { label: "Integrations", href: "https://example.com/integrations" },
                                        { label: "Support", href: "https://support.example.com" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="icon-arrow"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="mediumSmall"
            sizing="mediumLargeSizeMediumTitles"
            background="floatingGradient"
            cardStyle="solid"
            primaryButtonStyle="radial-glow"
            secondaryButtonStyle="solid"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="SaaS Pro"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </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="SaaS Pro"
                        copyrightText="© 2025 SaaS Pro. All rights reserved."
                        columns={[
                            {
                                title: "Product",                                items: [
                                    { label: "Features", href: "features" },
                                    { label: "Pricing", href: "pricing" },
                                    { label: "Security", href: "https://example.com/security" },
                                    { label: "Roadmap", href: "https://example.com/roadmap" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About", href: "https://example.com/about" },
                                    { label: "Blog", href: "https://example.com/blog" },
                                    { label: "Careers", href: "https://example.com/careers" },
                                    { label: "Contact", href: "contact" }
                                ]
                            },
                            {
                                title: "Resources",                                items: [
                                    { label: "Documentation", href: "https://docs.example.com" },
                                    { label: "API Reference", href: "https://api.example.com" },
                                    { label: "Integrations", href: "https://example.com/integrations" },
                                    { label: "Support", href: "https://support.example.com" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}