"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
import FooterBaseReveal from '@/components/sections/footer/FooterBaseReveal';
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="shift-hover"
                defaultTextAnimation="background-highlight"
                borderRadius="sharp"
                contentWidth="smallMedium"
                sizing="mediumLargeSizeLargeTitles"
                background="circleGradient"
                cardStyle="gradient-mesh"
                primaryButtonStyle="primary-glow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="Omakase Niseko"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                            className="backdrop-blur-md bg-black/40 border border-red-900/30"
                            navItemClassName="text-white hover:text-red-400 transition-colors"
                            buttonClassName="bg-red-600 hover:bg-red-700 text-white"
                            buttonTextClassName="font-bold"
                        />
                    </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="shift-hover"
            defaultTextAnimation="background-highlight"
            borderRadius="sharp"
            contentWidth="smallMedium"
            sizing="mediumLargeSizeLargeTitles"
            background="circleGradient"
            cardStyle="gradient-mesh"
            primaryButtonStyle="primary-glow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="Omakase Niseko"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                        className="backdrop-blur-md bg-black/40 border border-red-900/30"
                        navItemClassName="text-white hover:text-red-400 transition-colors"
                        buttonClassName="bg-red-600 hover:bg-red-700 text-white"
                        buttonTextClassName="font-bold"
                    />
                </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":"Experience","items":[{"label":"The Omakase","href":"#experience"},{"label":"Our Philosophy","href":"#about"},{"label":"Reservations","href":"#contact"}]},
                            {"title":"Location","items":[{"label":"Niseko, Hokkaido","href":"#"},{"label":"Hours: 5:00 PM - 11:00 PM","href":"#"},{"label":"Closed Mondays","href":"#"}]},
                            {"title":"Connect","items":[{"label":"Instagram","href":"https://instagram.com"},{"label":"Contact","href":"#contact"},{"label":"Inquiries","href":"mailto:info@omakaseniseko.com"}]}
                        ]}
                        copyrightText="© 2025 Omakase Niseko. All rights reserved."
                        className="w-full"
                        columnTitleClassName="text-white font-extrabold text-lg mb-4"
                        columnItemClassName="text-gray-400 hover:text-red-400 transition-colors text-sm mb-2"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}