"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingOverlay from '@/components/navbar/NavbarLayoutFloatingOverlay/NavbarLayoutFloatingOverlay';
import FooterLogoEmphasis from '@/components/sections/footer/FooterLogoEmphasis';
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="entrance-slide"
                borderRadius="sharp"
                contentWidth="compact"
                sizing="mediumLargeSizeMediumTitles"
                background="floatingGradient"
                cardStyle="soft-shadow"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="glass"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="ProStore"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "products" },
                                { name: "Reviews", id: "reviews" },
                                { name: "FAQ", id: "faq" },
                                { name: "Contact", id: "contact" }
                            ]}
                            button={{ text: "View 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="ProStore"
                            columns={[
                                {
                                    items: [
                                        { label: "Shop", href: "#products" },
                                        { label: "New Arrivals", href: "#" },
                                        { label: "Best Sellers", href: "#" },
                                        { label: "Sale", href: "#" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Support", href: "#" },
                                        { label: "Contact Us", href: "#contact" },
                                        { label: "FAQ", href: "#faq" },
                                        { label: "Shipping Info", href: "#" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Company", href: "#" },
                                        { label: "About Us", href: "#" },
                                        { label: "Careers", href: "#" },
                                        { label: "Blog", href: "#" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Legal", href: "#" },
                                        { label: "Privacy Policy", href: "#" },
                                        { label: "Terms of Service", href: "#" },
                                        { label: "Returns", href: "#" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="bounce-effect"
            defaultTextAnimation="entrance-slide"
            borderRadius="sharp"
            contentWidth="compact"
            sizing="mediumLargeSizeMediumTitles"
            background="floatingGradient"
            cardStyle="soft-shadow"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="glass"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="ProStore"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "products" },
                            { name: "Reviews", id: "reviews" },
                            { name: "FAQ", id: "faq" },
                            { name: "Contact", id: "contact" }
                        ]}
                        button={{ text: "View 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="ProStore"
                        columns={[
                            {
                                items: [
                                    { label: "Shop", href: "#products" },
                                    { label: "New Arrivals", href: "#" },
                                    { label: "Best Sellers", href: "#" },
                                    { label: "Sale", href: "#" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Support", href: "#" },
                                    { label: "Contact Us", href: "#contact" },
                                    { label: "FAQ", href: "#faq" },
                                    { label: "Shipping Info", href: "#" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Company", href: "#" },
                                    { label: "About Us", href: "#" },
                                    { label: "Careers", href: "#" },
                                    { label: "Blog", href: "#" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Legal", href: "#" },
                                    { label: "Privacy Policy", href: "#" },
                                    { label: "Terms of Service", href: "#" },
                                    { label: "Returns", href: "#" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}