"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
import FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
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="bounce-effect"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="smallMedium"
                sizing="mediumLargeSizeLargeTitles"
                background="circleGradient"
                cardStyle="gradient-bordered"
                primaryButtonStyle="flat"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="Carioca Constru & Co"
                            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>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="bounce-effect"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="smallMedium"
            sizing="mediumLargeSizeLargeTitles"
            background="circleGradient"
            cardStyle="gradient-bordered"
            primaryButtonStyle="flat"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="Carioca Constru & Co"
                        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">
                    <FooterBaseCard
                        logoText="Carioca Constru & Co"
                        columns={[
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "#about" },
                                    { label: "Our Services", href: "#features" },
                                    { label: "Projects", href: "#features" },
                                    { label: "Blog", href: "#blog" }
                                ]
                            },
                            {
                                title: "Resources",                                items: [
                                    { label: "Construction Guide", href: "#blog" },
                                    { label: "Sustainability", href: "#features" },
                                    { label: "FAQs", href: "#blog" },
                                    { label: "News", href: "#blog" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "Email: info@cariocaconstru.com", href: "mailto:info@cariocaconstru.com" },
                                    { label: "Phone: +55 21 3000-0000", href: "tel:+552130000000" },
                                    { label: "Rio de Janeiro, Brazil", href: "#" },
                                    { label: "Schedule Consultation", href: "#contact" }
                                ]
                            },
                            {
                                title: "Follow Us",                                items: [
                                    { label: "Instagram", href: "https://instagram.com" },
                                    { label: "LinkedIn", href: "https://linkedin.com" },
                                    { label: "Facebook", href: "https://facebook.com" },
                                    { label: "Twitter", href: "https://twitter.com" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 Carioca Constru & Co. All rights reserved. Building the future of Rio de Janeiro."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}