"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 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="expand-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="rounded"
                contentWidth="medium"
                sizing="largeSmallSizeMediumTitles"
                background="circleGradient"
                cardStyle="gradient-radial"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="layered"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="ShopHub"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" },
                                { 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">
                        <FooterBase
                            logoText="ShopHub"
                            copyrightText="© 2025 ShopHub. All rights reserved."
                            columns={[
                                {
                                    title: "Shop",                                    items: [
                                        { label: "Products", href: "/shop" },
                                        { label: "New Arrivals", href: "/shop" },
                                        { label: "Best Sellers", href: "/shop" },
                                        { label: "Sale", href: "/shop" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "/about" },
                                        { label: "Blog", href: "https://blog.shophub.com" },
                                        { label: "Careers", href: "https://careers.shophub.com" },
                                        { label: "Press", href: "https://press.shophub.com" }
                                    ]
                                },
                                {
                                    title: "Support",                                    items: [
                                        { label: "Help Center", href: "https://help.shophub.com" },
                                        { label: "Contact Us", href: "/contact" },
                                        { label: "Shipping Info", href: "https://shipping.shophub.com" },
                                        { label: "Returns", href: "https://returns.shophub.com" }
                                    ]
                                }
                            ]}
                            onPrivacyClick={() => window.location.href = '/privacy'}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="expand-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="rounded"
            contentWidth="medium"
            sizing="largeSmallSizeMediumTitles"
            background="circleGradient"
            cardStyle="gradient-radial"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="layered"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="ShopHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" },
                            { 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">
                    <FooterBase
                        logoText="ShopHub"
                        copyrightText="© 2025 ShopHub. All rights reserved."
                        columns={[
                            {
                                title: "Shop",                                items: [
                                    { label: "Products", href: "/shop" },
                                    { label: "New Arrivals", href: "/shop" },
                                    { label: "Best Sellers", href: "/shop" },
                                    { label: "Sale", href: "/shop" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "/about" },
                                    { label: "Blog", href: "https://blog.shophub.com" },
                                    { label: "Careers", href: "https://careers.shophub.com" },
                                    { label: "Press", href: "https://press.shophub.com" }
                                ]
                            },
                            {
                                title: "Support",                                items: [
                                    { label: "Help Center", href: "https://help.shophub.com" },
                                    { label: "Contact Us", href: "/contact" },
                                    { label: "Shipping Info", href: "https://shipping.shophub.com" },
                                    { label: "Returns", href: "https://returns.shophub.com" }
                                ]
                            }
                        ]}
                        onPrivacyClick={() => window.location.href = '/privacy'}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}