"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 {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    const [cartOpen, setCartOpen] = useState(false);

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="text-stagger"
                defaultTextAnimation="reveal-blur"
                borderRadius="pill"
                contentWidth="smallMedium"
                sizing="largeSmallSizeMediumTitles"
                background="aurora"
                cardStyle="layered-gradient"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="solid"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="PropertyHub"
                            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">
                        <FooterLogoEmphasis
                            logoText="PropertyHub"
                            columns={[
                                {
                                    items: [
                                        { label: "Market Insights", href: "#metrics" },
                                        { label: "Search Tips", href: "#features" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "About Us", href: "#about" },
                                        { label: "Our Team", href: "#" },
                                        { label: "Careers", href: "#" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Contact Support", href: "#contact" },
                                        { label: "Help Center", href: "#" },
                                        { label: "Feedback", href: "#" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Privacy Policy", href: "#" },
                                        { label: "Terms of Service", href: "#" },
                                        { label: "Cookie Settings", href: "#" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="smallMedium"
            sizing="largeSmallSizeMediumTitles"
            background="aurora"
            cardStyle="layered-gradient"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="solid"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="PropertyHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" },
                            { name: "Contact", id: "contact" }
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </div>
                <div id="product-catalog" data-section="product-catalog">
                    <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="PropertyHub"
                        columns={[
                            {
                                items: [
                                    { label: "Market Insights", href: "#metrics" },
                                    { label: "Search Tips", href: "#features" }
                                ]
                            },
                            {
                                items: [
                                    { label: "About Us", href: "#about" },
                                    { label: "Our Team", href: "#" },
                                    { label: "Careers", href: "#" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Contact Support", href: "#contact" },
                                    { label: "Help Center", href: "#" },
                                    { label: "Feedback", href: "#" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Privacy Policy", href: "#" },
                                    { label: "Terms of Service", href: "#" },
                                    { label: "Cookie Settings", href: "#" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}