"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 FooterBase from '@/components/sections/footer/FooterBase';
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="text-shift"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="compact"
                sizing="mediumSizeLargeTitles"
                background="floatingGradient"
                cardStyle="gradient-radial"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="normal"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "About", id: "about" },
                                { name: "Contact", id: "contact" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            brandName="PropertyHub"
                            bottomLeftText="Premium Real Estate"
                            bottomRightText="hello@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">
                        <FooterBase
                            logoText="PropertyHub"
                            columns={[
                                {
                                    title: "Product",                                    items: [
                                        { label: "Search Properties", href: "properties" },
                                        { label: "List Property", href: "https://seller.propertyhub.com" },
                                        { label: "Pricing", href: "featured" },
                                        { label: "Virtual Tours", href: "https://tours.propertyhub.com" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "about" },
                                        { label: "Blog", href: "blog" },
                                        { label: "Careers", href: "https://careers.propertyhub.com" },
                                        { label: "Contact", href: "contact" }
                                    ]
                                },
                                {
                                    title: "Legal",                                    items: [
                                        { label: "Privacy Policy", href: "https://propertyhub.com/privacy" },
                                        { label: "Terms of Service", href: "https://propertyhub.com/terms" },
                                        { label: "Cookie Policy", href: "https://propertyhub.com/cookies" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 PropertyHub | All rights reserved"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="compact"
            sizing="mediumSizeLargeTitles"
            background="floatingGradient"
            cardStyle="gradient-radial"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="normal"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "About", id: "about" },
                            { name: "Contact", id: "contact" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        brandName="PropertyHub"
                        bottomLeftText="Premium Real Estate"
                        bottomRightText="hello@propertyhub.com"
                        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">
                    <FooterBase
                        logoText="PropertyHub"
                        columns={[
                            {
                                title: "Product",                                items: [
                                    { label: "Search Properties", href: "properties" },
                                    { label: "List Property", href: "https://seller.propertyhub.com" },
                                    { label: "Pricing", href: "featured" },
                                    { label: "Virtual Tours", href: "https://tours.propertyhub.com" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "about" },
                                    { label: "Blog", href: "blog" },
                                    { label: "Careers", href: "https://careers.propertyhub.com" },
                                    { label: "Contact", href: "contact" }
                                ]
                            },
                            {
                                title: "Legal",                                items: [
                                    { label: "Privacy Policy", href: "https://propertyhub.com/privacy" },
                                    { label: "Terms of Service", href: "https://propertyhub.com/terms" },
                                    { label: "Cookie Policy", href: "https://propertyhub.com/cookies" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 PropertyHub | All rights reserved"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}