"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterMedia from '@/components/sections/footer/FooterMedia';
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="text-stagger"
                defaultTextAnimation="entrance-slide"
                borderRadius="rounded"
                contentWidth="medium"
                sizing="largeSizeMediumTitles"
                background="floatingGradient"
                cardStyle="gradient-mesh"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="layered"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="Paradise Resort"
                            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="text-stagger"
            defaultTextAnimation="entrance-slide"
            borderRadius="rounded"
            contentWidth="medium"
            sizing="largeSizeMediumTitles"
            background="floatingGradient"
            cardStyle="gradient-mesh"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="layered"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="Paradise Resort"
                        navItems={[
                            { name: "Home", id: "/" },
                            { 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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/umbrella-chair-around-swimming-pool-resort-hotel-leisure-travel-vacation_74190-8221.jpg"
                        imageAlt="Aerial view of Paradise Resort"
                        logoText="Paradise Resort"
                        copyrightText="© 2025 Paradise Resort. All rights reserved. Located in Puerto Rico."
                        columns={[
                            {
                                title: "Rooms & Suites",                                items: [
                                    { label: "Garden View Suite", href: "#pricing" },
                                    { label: "Beachfront Luxury", href: "#pricing" },
                                    { label: "Presidential Penthouse", href: "#pricing" }
                                ]
                            },
                            {
                                title: "Experiences",                                items: [
                                    { label: "Spa & Wellness", href: "#features" },
                                    { label: "Fine Dining", href: "#features" },
                                    { label: "Island Tours", href: "#" },
                                    { label: "Water Sports", href: "#" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "Reservations", href: "#contact" },
                                    { label: "Concierge", href: "#contact" },
                                    { label: "Press Inquiries", href: "#" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}