"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingOverlay from '@/components/navbar/NavbarLayoutFloatingOverlay/NavbarLayoutFloatingOverlay';
import FooterMedia from '@/components/sections/footer/FooterMedia';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
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="bounce-effect"
                defaultTextAnimation="reveal-blur"
                borderRadius="sharp"
                contentWidth="small"
                sizing="mediumSizeLargeTitles"
                background="aurora"
                cardStyle="gradient-mesh"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="ShopHub"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" },
                                { 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">
                        <FooterMedia
                            imageSrc="https://img.b2bpic.net/free-photo/woman-studio-lamp-photo-art-concept_23-2148565571.jpg"
                            imageAlt="ShopHub footer showcase"
                            logoText="ShopHub"
                            copyrightText="© 2025 ShopHub. All rights reserved."
                            columns={[
                                {
                                    title: "Shop",                                    items: [
                                        { label: "Products", href: "/shop" },
                                        { label: "Categories", href: "/shop" },
                                        { label: "New Arrivals", href: "/shop" },
                                        { label: "Best Sellers", href: "/shop" }
                                    ]
                                },
                                {
                                    title: "Support",                                    items: [
                                        { label: "Contact Us", href: "/contact" },
                                        { label: "Shipping Info", href: "/shop" },
                                        { label: "Returns", href: "/shop" },
                                        { label: "FAQ", href: "/shop" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "/" },
                                        { label: "Privacy Policy", href: "/" },
                                        { label: "Terms of Service", href: "/" },
                                        { label: "Careers", href: "/" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="bounce-effect"
            defaultTextAnimation="reveal-blur"
            borderRadius="sharp"
            contentWidth="small"
            sizing="mediumSizeLargeTitles"
            background="aurora"
            cardStyle="gradient-mesh"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="ShopHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" },
                            { 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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/woman-studio-lamp-photo-art-concept_23-2148565571.jpg"
                        imageAlt="ShopHub footer showcase"
                        logoText="ShopHub"
                        copyrightText="© 2025 ShopHub. All rights reserved."
                        columns={[
                            {
                                title: "Shop",                                items: [
                                    { label: "Products", href: "/shop" },
                                    { label: "Categories", href: "/shop" },
                                    { label: "New Arrivals", href: "/shop" },
                                    { label: "Best Sellers", href: "/shop" }
                                ]
                            },
                            {
                                title: "Support",                                items: [
                                    { label: "Contact Us", href: "/contact" },
                                    { label: "Shipping Info", href: "/shop" },
                                    { label: "Returns", href: "/shop" },
                                    { label: "FAQ", href: "/shop" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "/" },
                                    { label: "Privacy Policy", href: "/" },
                                    { label: "Terms of Service", href: "/" },
                                    { label: "Careers", href: "/" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}