"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleApple from '@/components/navbar/NavbarStyleApple/NavbarStyleApple';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterBaseReveal from '@/components/sections/footer/FooterBaseReveal';
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="background-highlight"
                borderRadius="soft"
                contentWidth="smallMedium"
                sizing="largeSizeMediumTitles"
                background="floatingGradient"
                cardStyle="elevated"
                primaryButtonStyle="flat"
                secondaryButtonStyle="solid"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="Aesthetic Grace"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "About", id: "about" },
                                { name: "Services", id: "services" },
                                { name: "Gallery", id: "gallery" },
                                { name: "Team", id: "team" },
                                { 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">
                        <FooterBaseReveal
                            columns={[
                                {
                                    title: "Services",                                    items: [
                                        { label: "Facelift", href: "services" },
                                        { label: "Rhinoplasty", href: "services" },
                                        { label: "Breast Surgery", href: "services" },
                                        { label: "Body Contouring", href: "services" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "about" },
                                        { label: "Our Team", href: "team" },
                                        { label: "Gallery", href: "gallery" },
                                        { label: "Contact", href: "contact" }
                                    ]
                                },
                                {
                                    title: "Contact",                                    items: [
                                        { label: "San Diego, CA", href: "#" },
                                        { label: "(619) 555-1234", href: "tel:+16195551234" },
                                        { label: "info@aestheticgracesd.com", href: "mailto:info@aestheticgracesd.com" },
                                        { label: "Mon - Fri: 9AM - 6PM", href: "#" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 Aesthetic Grace. All rights reserved. Board-Certified Excellence in Cosmetic Surgery."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="bounce-effect"
            defaultTextAnimation="background-highlight"
            borderRadius="soft"
            contentWidth="smallMedium"
            sizing="largeSizeMediumTitles"
            background="floatingGradient"
            cardStyle="elevated"
            primaryButtonStyle="flat"
            secondaryButtonStyle="solid"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="Aesthetic Grace"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "About", id: "about" },
                            { name: "Services", id: "services" },
                            { name: "Gallery", id: "gallery" },
                            { name: "Team", id: "team" },
                            { 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">
                    <FooterBaseReveal
                        columns={[
                            {
                                title: "Services",                                items: [
                                    { label: "Facelift", href: "services" },
                                    { label: "Rhinoplasty", href: "services" },
                                    { label: "Breast Surgery", href: "services" },
                                    { label: "Body Contouring", href: "services" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "about" },
                                    { label: "Our Team", href: "team" },
                                    { label: "Gallery", href: "gallery" },
                                    { label: "Contact", href: "contact" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "San Diego, CA", href: "#" },
                                    { label: "(619) 555-1234", href: "tel:+16195551234" },
                                    { label: "info@aestheticgracesd.com", href: "mailto:info@aestheticgracesd.com" },
                                    { label: "Mon - Fri: 9AM - 6PM", href: "#" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 Aesthetic Grace. All rights reserved. Board-Certified Excellence in Cosmetic Surgery."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}