"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterSimple from '@/components/sections/footer/FooterSimple';
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="directional-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="rounded"
                contentWidth="mediumSmall"
                sizing="large"
                background="floatingGradient"
                cardStyle="gradient-bordered"
                primaryButtonStyle="flat"
                secondaryButtonStyle="layered"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            brandName="PropertyHub"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Browse", id: "properties" },
                                { name: "About", id: "about" },
                                { name: "Contact", id: "contact" },
                                { name: "Resources", id: "resources" },
                                { name: "Sign In", id: "signin" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            bottomLeftText="Real Estate Solutions"
                            bottomRightText="info@propertyhub.com"
                            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: "Browse",                                    items: [
                                        { label: "All Properties", href: "#properties" },
                                        { label: "New Listings", href: "#properties" },
                                        { label: "Featured", href: "#products" },
                                        { label: "Price Guide", href: "#" }
                                    ]
                                },
                                {
                                    title: "Resources",                                    items: [
                                        { label: "Buyer's Guide", href: "#" },
                                        { label: "Market Insights", href: "#" },
                                        { label: "Investment Tips", href: "#" },
                                        { label: "Blog", href: "#" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "#" },
                                        { label: "Contact", href: "#contact" },
                                        { label: "Careers", href: "#" },
                                        { label: "Press", href: "#" }
                                    ]
                                },
                                {
                                    title: "Legal",                                    items: [
                                        { label: "Privacy Policy", href: "#" },
                                        { label: "Terms & Conditions", href: "#" },
                                        { label: "Disclaimer", href: "#" },
                                        { label: "Accessibility", href: "#" }
                                    ]
                                }
                            ]}
                            bottomLeftText="© 2025 PropertyHub. All rights reserved."
                            bottomRightText="Made with PropertyHub"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="directional-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="rounded"
            contentWidth="mediumSmall"
            sizing="large"
            background="floatingGradient"
            cardStyle="gradient-bordered"
            primaryButtonStyle="flat"
            secondaryButtonStyle="layered"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        brandName="PropertyHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Browse", id: "properties" },
                            { name: "About", id: "about" },
                            { name: "Contact", id: "contact" },
                            { name: "Resources", id: "resources" },
                            { name: "Sign In", id: "signin" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        bottomLeftText="Real Estate Solutions"
                        bottomRightText="info@propertyhub.com"
                        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">
                    <FooterSimple
                        columns={[
                            {
                                title: "Browse",                                items: [
                                    { label: "All Properties", href: "#properties" },
                                    { label: "New Listings", href: "#properties" },
                                    { label: "Featured", href: "#products" },
                                    { label: "Price Guide", href: "#" }
                                ]
                            },
                            {
                                title: "Resources",                                items: [
                                    { label: "Buyer's Guide", href: "#" },
                                    { label: "Market Insights", href: "#" },
                                    { label: "Investment Tips", href: "#" },
                                    { label: "Blog", href: "#" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "#" },
                                    { label: "Contact", href: "#contact" },
                                    { label: "Careers", href: "#" },
                                    { label: "Press", href: "#" }
                                ]
                            },
                            {
                                title: "Legal",                                items: [
                                    { label: "Privacy Policy", href: "#" },
                                    { label: "Terms & Conditions", href: "#" },
                                    { label: "Disclaimer", href: "#" },
                                    { label: "Accessibility", href: "#" }
                                ]
                            }
                        ]}
                        bottomLeftText="© 2025 PropertyHub. All rights reserved."
                        bottomRightText="Made with PropertyHub"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}