"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
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="icon-arrow"
                defaultTextAnimation="background-highlight"
                borderRadius="soft"
                contentWidth="mediumLarge"
                sizing="medium"
                background="aurora"
                cardStyle="solid"
                primaryButtonStyle="flat"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"About","id":"about"},
                                {"name":"Menu","id":"menu"},
                                {"name":"Gallery","id":"gallery"},
                                {"name":"Reservations","id":"reservations"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            brandName="Savour"
                            bottomLeftText="Fine Dining Experience"
                            bottomRightText="hello@savour.restaurant"
                            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":"Dine","items":[{"label":"Menu","href":"#menu"},{"label":"Reservations","href":"#reservations"},{"label":"Private Events","href":"#"}]},
                                {"title":"Connect","items":[{"label":"About","href":"#about"},{"label":"Gallery","href":"#gallery"},{"label":"Contact","href":"#reservations"}]},
                                {"title":"Contact","items":[{"label":"hello@savour.restaurant","href":"mailto:hello@savour.restaurant"},{"label":"(555) 123-4567","href":"tel:+15551234567"},{"label":"123 Culinary Lane, Gastro City, GC 12345","href":"#"}]}
                            ]}
                            copyrightText="© 2025 Savour Restaurant | Crafting Memories, One Dish at a Time"
                            className="w-full"
                            containerClassName="w-full"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="icon-arrow"
            defaultTextAnimation="background-highlight"
            borderRadius="soft"
            contentWidth="mediumLarge"
            sizing="medium"
            background="aurora"
            cardStyle="solid"
            primaryButtonStyle="flat"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"About","id":"about"},
                            {"name":"Menu","id":"menu"},
                            {"name":"Gallery","id":"gallery"},
                            {"name":"Reservations","id":"reservations"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        brandName="Savour"
                        bottomLeftText="Fine Dining Experience"
                        bottomRightText="hello@savour.restaurant"
                        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">
                    <FooterBaseReveal
                        columns={[
                            {"title":"Dine","items":[{"label":"Menu","href":"#menu"},{"label":"Reservations","href":"#reservations"},{"label":"Private Events","href":"#"}]},
                            {"title":"Connect","items":[{"label":"About","href":"#about"},{"label":"Gallery","href":"#gallery"},{"label":"Contact","href":"#reservations"}]},
                            {"title":"Contact","items":[{"label":"hello@savour.restaurant","href":"mailto:hello@savour.restaurant"},{"label":"(555) 123-4567","href":"tel:+15551234567"},{"label":"123 Culinary Lane, Gastro City, GC 12345","href":"#"}]}
                        ]}
                        copyrightText="© 2025 Savour Restaurant | Crafting Memories, One Dish at a Time"
                        className="w-full"
                        containerClassName="w-full"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}