"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
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 {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });
    
    const [cartOpen, setCartOpen] = useState(false);

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="text-stagger"
                defaultTextAnimation="entrance-slide"
                borderRadius="rounded"
                contentWidth="compact"
                sizing="mediumLarge"
                background="aurora"
                cardStyle="gradient-bordered"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="HomeFind"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Listings","id":"properties"},
                                {"name":"About","id":"about"},
                                {"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">
                        <FooterMedia
                            imageSrc="https://img.b2bpic.net/free-photo/beach-chair-resort_1150-17976.jpg"
                            imageAlt="Real estate community and neighborhoods"
                            columns={[
                                {"title":"Browse","items":[{"label":"All Properties","href":"#properties"},{"label":"Featured Listings","href":"#featured"},{"label":"Search","href":"#search-filters"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Contact","href":"#contact"},{"label":"Careers","href":"#"},{"label":"Blog","href":"#"}]},
                                {"title":"Support","items":[{"label":"Help Center","href":"#"},{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"Contact Support","href":"#contact"}]}
                            ]}
                            logoText="HomeFind"
                            copyrightText="© 2025 HomeFind Real Estate. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="entrance-slide"
            borderRadius="rounded"
            contentWidth="compact"
            sizing="mediumLarge"
            background="aurora"
            cardStyle="gradient-bordered"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="HomeFind"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Listings","id":"properties"},
                            {"name":"About","id":"about"},
                            {"name":"Contact","id":"contact"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/beach-chair-resort_1150-17976.jpg"
                        imageAlt="Real estate community and neighborhoods"
                        columns={[
                            {"title":"Browse","items":[{"label":"All Properties","href":"#properties"},{"label":"Featured Listings","href":"#featured"},{"label":"Search","href":"#search-filters"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Contact","href":"#contact"},{"label":"Careers","href":"#"},{"label":"Blog","href":"#"}]},
                            {"title":"Support","items":[{"label":"Help Center","href":"#"},{"label":"Privacy Policy","href":"#"},{"label":"Terms of Service","href":"#"},{"label":"Contact Support","href":"#contact"}]}
                        ]}
                        logoText="HomeFind"
                        copyrightText="© 2025 HomeFind Real Estate. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}