"use client";

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

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

    const {
        isOpen: cartOpen,
        setIsOpen: setCartOpen,
    } = useCart();

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="hover-magnetic"
                defaultTextAnimation="entrance-slide"
                borderRadius="sharp"
                contentWidth="medium"
                sizing="mediumLargeSizeMediumTitles"
                background="aurora"
                cardStyle="soft-shadow"
                primaryButtonStyle="flat"
                secondaryButtonStyle="solid"
                headingFontWeight="bold"
            >
                <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">
                        <FooterSimple
                            columns={[
                                {
                                    title: "Product",                                    items: [
                                        { label: "Features", href: "#features" },
                                        { label: "Pricing", href: "#pricing" },
                                        { label: "Security", href: "https://example.com/security" },
                                        { label: "Integrations", href: "https://example.com/integrations" }
                                    ]
                                },
                                {
                                    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://example.com/docs" },
                                        { label: "Help Center", href: "https://example.com/help" },
                                        { label: "API Reference", href: "https://example.com/api" },
                                        { 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: "Cookie Policy", href: "https://example.com/cookies" },
                                        { label: "Status Page", href: "https://example.com/status" }
                                    ]
                                }
                            ]}
                            bottomLeftText="© 2025 SaaS Pro. All rights reserved."
                            bottomRightText="Designed & Built for Modern Teams"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-magnetic"
            defaultTextAnimation="entrance-slide"
            borderRadius="sharp"
            contentWidth="medium"
            sizing="mediumLargeSizeMediumTitles"
            background="aurora"
            cardStyle="soft-shadow"
            primaryButtonStyle="flat"
            secondaryButtonStyle="solid"
            headingFontWeight="bold"
        >
            <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="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">
                    <FooterSimple
                        columns={[
                            {
                                title: "Product",                                items: [
                                    { label: "Features", href: "#features" },
                                    { label: "Pricing", href: "#pricing" },
                                    { label: "Security", href: "https://example.com/security" },
                                    { label: "Integrations", href: "https://example.com/integrations" }
                                ]
                            },
                            {
                                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://example.com/docs" },
                                    { label: "Help Center", href: "https://example.com/help" },
                                    { label: "API Reference", href: "https://example.com/api" },
                                    { 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: "Cookie Policy", href: "https://example.com/cookies" },
                                    { label: "Status Page", href: "https://example.com/status" }
                                ]
                            }
                        ]}
                        bottomLeftText="© 2025 SaaS Pro. All rights reserved."
                        bottomRightText="Designed & Built for Modern Teams"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}