"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 FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
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="slide-background"
                defaultTextAnimation="entrance-slide"
                borderRadius="rounded"
                contentWidth="compact"
                sizing="mediumLargeSizeLargeTitles"
                background="aurora"
                cardStyle="glass-elevated"
                primaryButtonStyle="shadow"
                secondaryButtonStyle="glass"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="Omakase Niseko"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Experience", id: "experience" },
                                { name: "Pricing", id: "pricing" },
                                { name: "Chefs", id: "team" },
                                { name: "Reviews", id: "testimonials" },
                                { name: "Reserve", 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">
                        <FooterBaseCard
                            logoText="Omakase Niseko"
                            columns={[
                                {
                                    title: "Experience",                                    items: [
                                        { label: "Our Philosophy", href: "#about" },
                                        { label: "Omakase Tiers", href: "#pricing" },
                                        { label: "The Chefs", href: "#team" },
                                        { label: "Reviews", href: "#testimonials" }
                                    ]
                                },
                                {
                                    title: "Reservations",                                    items: [
                                        { label: "Book Now", href: "#contact" },
                                        { label: "Group Events", href: "#contact" },
                                        { label: "Private Experiences", href: "#contact" },
                                        { label: "Cancellation Policy", href: "#" }
                                    ]
                                },
                                {
                                    title: "Contact",                                    items: [
                                        { label: "Location", href: "#" },
                                        { label: "Hours", href: "#" },
                                        { label: "Email", href: "mailto:reserve@omakase-niseko.jp" },
                                        { label: "Phone", href: "tel:+81-136-22-0008" }
                                    ]
                                },
                                {
                                    title: "Connect",                                    items: [
                                        { label: "Instagram", href: "https://instagram.com" },
                                        { label: "Facebook", href: "https://facebook.com" },
                                        { label: "Newsletter", href: "#contact" },
                                        { label: "Blog", href: "#" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 Omakase Niseko. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="slide-background"
            defaultTextAnimation="entrance-slide"
            borderRadius="rounded"
            contentWidth="compact"
            sizing="mediumLargeSizeLargeTitles"
            background="aurora"
            cardStyle="glass-elevated"
            primaryButtonStyle="shadow"
            secondaryButtonStyle="glass"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="Omakase Niseko"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Experience", id: "experience" },
                            { name: "Pricing", id: "pricing" },
                            { name: "Chefs", id: "team" },
                            { name: "Reviews", id: "testimonials" },
                            { name: "Reserve", 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">
                    <FooterBaseCard
                        logoText="Omakase Niseko"
                        columns={[
                            {
                                title: "Experience",                                items: [
                                    { label: "Our Philosophy", href: "#about" },
                                    { label: "Omakase Tiers", href: "#pricing" },
                                    { label: "The Chefs", href: "#team" },
                                    { label: "Reviews", href: "#testimonials" }
                                ]
                            },
                            {
                                title: "Reservations",                                items: [
                                    { label: "Book Now", href: "#contact" },
                                    { label: "Group Events", href: "#contact" },
                                    { label: "Private Experiences", href: "#contact" },
                                    { label: "Cancellation Policy", href: "#" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "Location", href: "#" },
                                    { label: "Hours", href: "#" },
                                    { label: "Email", href: "mailto:reserve@omakase-niseko.jp" },
                                    { label: "Phone", href: "tel:+81-136-22-0008" }
                                ]
                            },
                            {
                                title: "Connect",                                items: [
                                    { label: "Instagram", href: "https://instagram.com" },
                                    { label: "Facebook", href: "https://facebook.com" },
                                    { label: "Newsletter", href: "#contact" },
                                    { label: "Blog", href: "#" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 Omakase Niseko. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}