"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
import FooterSimple from '@/components/sections/footer/FooterSimple';
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="text-stagger"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="medium"
                sizing="largeSmall"
                background="aurora"
                cardStyle="glass-elevated"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="Culinary Haven"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Menu","id":"menu"},
                                {"name":"Gallery","id":"gallery"},
                                {"name":"About","id":"about"},
                                {"name":"Reservations","id":"reservations"},
                                {"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">
                        <FooterSimple
                            columns={[
                                {"title":"Restaurant","items":[{"label":"Menu","href":"#menu"},{"label":"Gallery","href":"#gallery"},{"label":"Reservations","href":"#reservations"}]},
                                {"title":"Information","items":[{"label":"About Us","href":"#"},{"label":"Our Chef","href":"#"},{"label":"Events","href":"#"}]},
                                {"title":"Contact","items":[{"label":"Phone","href":"#"},{"label":"Email","href":"#"},{"label":"Location","href":"#"}]}
                            ]}
                            bottomLeftText="© 2025 Culinary Haven. All rights reserved."
                            bottomRightText="Made with Webild"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="medium"
            sizing="largeSmall"
            background="aurora"
            cardStyle="glass-elevated"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="Culinary Haven"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Menu","id":"menu"},
                            {"name":"Gallery","id":"gallery"},
                            {"name":"About","id":"about"},
                            {"name":"Reservations","id":"reservations"},
                            {"name":"Contact","id":"contact"},
                            {"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">
                    <FooterSimple
                        columns={[
                            {"title":"Restaurant","items":[{"label":"Menu","href":"#menu"},{"label":"Gallery","href":"#gallery"},{"label":"Reservations","href":"#reservations"}]},
                            {"title":"Information","items":[{"label":"About Us","href":"#"},{"label":"Our Chef","href":"#"},{"label":"Events","href":"#"}]},
                            {"title":"Contact","items":[{"label":"Phone","href":"#"},{"label":"Email","href":"#"},{"label":"Location","href":"#"}]}
                        ]}
                        bottomLeftText="© 2025 Culinary Haven. All rights reserved."
                        bottomRightText="Made with Webild"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}