"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterSimple from '@/components/sections/footer/FooterSimple';
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="text-stagger"
                defaultTextAnimation="entrance-slide"
                borderRadius="sharp"
                contentWidth="compact"
                sizing="mediumLarge"
                background="floatingGradient"
                cardStyle="gradient-radial"
                primaryButtonStyle="shadow"
                secondaryButtonStyle="glass"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="Luxe"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "products" },
                                { name: "About", id: "about" },
                                { name: "Reviews", id: "reviews" },
                                { name: "Contact", id: "contact" }
                            ]}
                            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: "Shop",                                    items: [
                                        { label: "All Products", href: "#" },
                                        { label: "New Arrivals", href: "#" },
                                        { label: "Best Sellers", href: "#" },
                                        { label: "Sale", href: "#" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "#" },
                                        { label: "Our Story", href: "#" },
                                        { label: "Sustainability", href: "#" },
                                        { label: "Careers", href: "#" }
                                    ]
                                },
                                {
                                    title: "Support",                                    items: [
                                        { label: "Contact Us", href: "#" },
                                        { label: "Shipping Info", href: "#" },
                                        { label: "Returns", href: "#" },
                                        { label: "FAQ", href: "#" }
                                    ]
                                }
                            ]}
                            bottomLeftText="© 2025 Luxe Essentials. All rights reserved."
                            bottomRightText="Crafted with excellence"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="entrance-slide"
            borderRadius="sharp"
            contentWidth="compact"
            sizing="mediumLarge"
            background="floatingGradient"
            cardStyle="gradient-radial"
            primaryButtonStyle="shadow"
            secondaryButtonStyle="glass"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="Luxe"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "products" },
                            { name: "About", id: "about" },
                            { name: "Reviews", id: "reviews" },
                            { name: "Contact", id: "contact" }
                        ]}
                        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">
                    <FooterSimple
                        columns={[
                            {
                                title: "Shop",                                items: [
                                    { label: "All Products", href: "#" },
                                    { label: "New Arrivals", href: "#" },
                                    { label: "Best Sellers", href: "#" },
                                    { label: "Sale", href: "#" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "#" },
                                    { label: "Our Story", href: "#" },
                                    { label: "Sustainability", href: "#" },
                                    { label: "Careers", href: "#" }
                                ]
                            },
                            {
                                title: "Support",                                items: [
                                    { label: "Contact Us", href: "#" },
                                    { label: "Shipping Info", href: "#" },
                                    { label: "Returns", href: "#" },
                                    { label: "FAQ", href: "#" }
                                ]
                            }
                        ]}
                        bottomLeftText="© 2025 Luxe Essentials. All rights reserved."
                        bottomRightText="Crafted with excellence"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}