"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingOverlay from '@/components/navbar/NavbarLayoutFloatingOverlay/NavbarLayoutFloatingOverlay';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterLogoEmphasis from '@/components/sections/footer/FooterLogoEmphasis';
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="slide-background"
                defaultTextAnimation="reveal-blur"
                borderRadius="soft"
                contentWidth="smallMedium"
                sizing="medium"
                background="none"
                cardStyle="soft-shadow"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="glass"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="LuxeShop"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "products" },
                                { name: "About", id: "about" },
                                { name: "Contact", id: "contact" },
                                { name: "Cart", id: "cart" }
                            ]}
                            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">
                        <FooterLogoEmphasis
                            logoText="LuxeShop"
                            columns={[
                                {
                                    items: [
                                        { label: "Shop", href: "shop" },
                                        { label: "New Arrivals", href: "new-arrivals" },
                                        { label: "Collections", href: "collections" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "About Us", href: "about" },
                                        { label: "Our Story", href: "story" },
                                        { label: "Craftsmanship", href: "craftsmanship" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Customer Care", href: "support" },
                                        { label: "Shipping Info", href: "shipping" },
                                        { label: "Returns", href: "returns" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Contact", href: "contact" },
                                        { label: "Privacy Policy", href: "privacy" },
                                        { label: "Terms of Service", href: "terms" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Follow Us", href: "https://instagram.com" },
                                        { label: "Facebook", href: "https://facebook.com" },
                                        { label: "Pinterest", href: "https://pinterest.com" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="slide-background"
            defaultTextAnimation="reveal-blur"
            borderRadius="soft"
            contentWidth="smallMedium"
            sizing="medium"
            background="none"
            cardStyle="soft-shadow"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="glass"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="LuxeShop"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "products" },
                            { name: "About", id: "about" },
                            { name: "Contact", id: "contact" },
                            { name: "Cart", id: "cart" }
                        ]}
                        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">
                    <FooterLogoEmphasis
                        logoText="LuxeShop"
                        columns={[
                            {
                                items: [
                                    { label: "Shop", href: "shop" },
                                    { label: "New Arrivals", href: "new-arrivals" },
                                    { label: "Collections", href: "collections" }
                                ]
                            },
                            {
                                items: [
                                    { label: "About Us", href: "about" },
                                    { label: "Our Story", href: "story" },
                                    { label: "Craftsmanship", href: "craftsmanship" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Customer Care", href: "support" },
                                    { label: "Shipping Info", href: "shipping" },
                                    { label: "Returns", href: "returns" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Contact", href: "contact" },
                                    { label: "Privacy Policy", href: "privacy" },
                                    { label: "Terms of Service", href: "terms" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Follow Us", href: "https://instagram.com" },
                                    { label: "Facebook", href: "https://facebook.com" },
                                    { label: "Pinterest", href: "https://pinterest.com" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}