"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleApple from "@/components/navbar/NavbarStyleApple/NavbarStyleApple";
import FooterSimple from "@/components/sections/footer/FooterSimple";
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="slide-background"
                defaultTextAnimation="background-highlight"
                borderRadius="pill"
                contentWidth="small"
                sizing="mediumLargeSizeLargeTitles"
                background="none"
                cardStyle="glass-elevated"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="layered"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="PropertyHub"
                            navItems={[
                                { name: "Home", id: "/" },
                                { 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">
                        <FooterSimple
                            columns={[
                                {
                                    title: "Explore",                                    items: [
                                        { label: "Browse Listings", href: "#properties" },
                                        { label: "Search Properties", href: "#search-filters" },
                                        { label: "View Map", href: "#map-integration" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "#about" },
                                        { label: "Our Agents", href: "#" },
                                        { label: "Testimonials", href: "#testimonials" }
                                    ]
                                },
                                {
                                    title: "Support",                                    items: [
                                        { label: "Contact Us", href: "#cta" },
                                        { label: "FAQ", href: "#cta" },
                                        { label: "Schedule Tour", href: "#" }
                                    ]
                                },
                                {
                                    title: "Resources",                                    items: [
                                        { label: "Buying Guide", href: "#" },
                                        { label: "Market Trends", href: "#" },
                                        { label: "Blog", href: "#" }
                                    ]
                                }
                            ]}
                            bottomLeftText="© 2025 PropertyHub. All rights reserved."
                            bottomRightText="Connecting buyers with their dream homes"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="slide-background"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="small"
            sizing="mediumLargeSizeLargeTitles"
            background="none"
            cardStyle="glass-elevated"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="layered"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="PropertyHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { 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">
                    <FooterSimple
                        columns={[
                            {
                                title: "Explore",                                items: [
                                    { label: "Browse Listings", href: "#properties" },
                                    { label: "Search Properties", href: "#search-filters" },
                                    { label: "View Map", href: "#map-integration" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "#about" },
                                    { label: "Our Agents", href: "#" },
                                    { label: "Testimonials", href: "#testimonials" }
                                ]
                            },
                            {
                                title: "Support",                                items: [
                                    { label: "Contact Us", href: "#cta" },
                                    { label: "FAQ", href: "#cta" },
                                    { label: "Schedule Tour", href: "#" }
                                ]
                            },
                            {
                                title: "Resources",                                items: [
                                    { label: "Buying Guide", href: "#" },
                                    { label: "Market Trends", href: "#" },
                                    { label: "Blog", href: "#" }
                                ]
                            }
                        ]}
                        bottomLeftText="© 2025 PropertyHub. All rights reserved."
                        bottomRightText="Connecting buyers with their dream homes"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}