"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 FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
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="rounded"
                contentWidth="small"
                sizing="largeSmall"
                background="floatingGradient"
                cardStyle="elevated"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="PropertyHub"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Browse", id: "properties" },
                                { name: "About", id: "about" },
                                { name: "How It Works", id: "features" },
                                { name: "FAQ", id: "faq" },
                                { name: "Contact", id: "contact" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            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">
                        <FooterBaseCard
                            logoText="PropertyHub"
                            columns={[
                                {
                                    title: "Explore",                                    items: [
                                        { label: "Browse Listings", href: "#properties" },
                                        { label: "Advanced Search", href: "#search-filters" },
                                        { label: "Market Reports", href: "#" },
                                        { label: "Investment Guide", href: "#" }
                                    ]
                                },
                                {
                                    title: "For Sellers",                                    items: [
                                        { label: "List Your Property", href: "https://example.com/list" },
                                        { label: "Pricing Guide", href: "#" },
                                        { label: "Selling Timeline", href: "#" },
                                        { label: "Success Stories", href: "#testimonials" }
                                    ]
                                },
                                {
                                    title: "Resources",                                    items: [
                                        { label: "Buyer's Guide", href: "#" },
                                        { label: "Financing Options", href: "#" },
                                        { label: "Market Insights", href: "#" },
                                        { label: "Blog", href: "#" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "#about" },
                                        { label: "Contact", href: "#contact" },
                                        { label: "Careers", href: "#" },
                                        { label: "Press", href: "#" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 PropertyHub. All rights reserved."
                            onPrivacyClick={null}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="slide-background"
            defaultTextAnimation="reveal-blur"
            borderRadius="rounded"
            contentWidth="small"
            sizing="largeSmall"
            background="floatingGradient"
            cardStyle="elevated"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="PropertyHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Browse", id: "properties" },
                            { name: "About", id: "about" },
                            { name: "How It Works", id: "features" },
                            { name: "FAQ", id: "faq" },
                            { name: "Contact", id: "contact" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        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">
                    <FooterBaseCard
                        logoText="PropertyHub"
                        columns={[
                            {
                                title: "Explore",                                items: [
                                    { label: "Browse Listings", href: "#properties" },
                                    { label: "Advanced Search", href: "#search-filters" },
                                    { label: "Market Reports", href: "#" },
                                    { label: "Investment Guide", href: "#" }
                                ]
                            },
                            {
                                title: "For Sellers",                                items: [
                                    { label: "List Your Property", href: "https://example.com/list" },
                                    { label: "Pricing Guide", href: "#" },
                                    { label: "Selling Timeline", href: "#" },
                                    { label: "Success Stories", href: "#testimonials" }
                                ]
                            },
                            {
                                title: "Resources",                                items: [
                                    { label: "Buyer's Guide", href: "#" },
                                    { label: "Financing Options", href: "#" },
                                    { label: "Market Insights", href: "#" },
                                    { label: "Blog", href: "#" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "#about" },
                                    { label: "Contact", href: "#contact" },
                                    { label: "Careers", href: "#" },
                                    { label: "Press", href: "#" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 PropertyHub. All rights reserved."
                        onPrivacyClick={null}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}