"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="slide-background"
                defaultTextAnimation="background-highlight"
                borderRadius="sharp"
                contentWidth="compact"
                sizing="largeSmallSizeMediumTitles"
                background="circleGradient"
                cardStyle="gradient-bordered"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="glass"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="PropertyHub"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Browse","id":"featured"},
                                {"name":"Search","id":"search"},
                                {"name":"Map View","id":"map"},
                                {"name":"Reviews","id":"testimonials"},
                                {"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">
                        <FooterLogoEmphasis
                            logoText="PropertyHub"
                            columns={[
                                {"items":[{"label":"Browse Properties","href":"#featured"},{"label":"Advanced Search","href":"#search"},{"label":"Map View","href":"#map"}]},
                                {"items":[{"label":"For Sellers","href":"#"},{"label":"List Property","href":"#"},{"label":"Marketing Tools","href":"#"}]},
                                {"items":[{"label":"Resources","href":"#"},{"label":"Market Guide","href":"#"},{"label":"FAQ","href":"#contact"}]},
                                {"items":[{"label":"About Us","href":"#"},{"label":"Contact","href":"#contact"},{"label":"Careers","href":"#"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="slide-background"
            defaultTextAnimation="background-highlight"
            borderRadius="sharp"
            contentWidth="compact"
            sizing="largeSmallSizeMediumTitles"
            background="circleGradient"
            cardStyle="gradient-bordered"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="glass"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="PropertyHub"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Browse","id":"featured"},
                            {"name":"Search","id":"search"},
                            {"name":"Map View","id":"map"},
                            {"name":"Reviews","id":"testimonials"},
                            {"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">
                    <FooterLogoEmphasis
                        logoText="PropertyHub"
                        columns={[
                            {"items":[{"label":"Browse Properties","href":"#featured"},{"label":"Advanced Search","href":"#search"},{"label":"Map View","href":"#map"}]},
                            {"items":[{"label":"For Sellers","href":"#"},{"label":"List Property","href":"#"},{"label":"Marketing Tools","href":"#"}]},
                            {"items":[{"label":"Resources","href":"#"},{"label":"Market Guide","href":"#"},{"label":"FAQ","href":"#contact"}]},
                            {"items":[{"label":"About Us","href":"#"},{"label":"Contact","href":"#contact"},{"label":"Careers","href":"#"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}