"use client"; /** * MENU PAGE — Premium Sidebar Navigation */ import { useEffect, useState, useMemo } from "react"; import { menuCategories } from "@/lib/menu-data"; import { gsap } from "gsap"; import { ScrollTrigger } from "gsap/ScrollTrigger"; import Navbar from "@/components/Navbar"; import Footer from "@/components/Footer"; import { useCart } from "@/components/CartContext"; import { useLanguage } from "@/lib/language-context"; import { getTranslation } from "@/lib/translations"; gsap.registerPlugin(ScrollTrigger); export default function MenuPage() { const [activeCategory, setActiveCategory] = useState("All"); const [searchQuery, setSearchQuery] = useState(""); const [showVegetarianOnly, setShowVegetarianOnly] = useState(false); const [isMobile, setIsMobile] = useState(false); const { addToCart } = useCart(); const { language } = useLanguage(); const t = getTranslation(language); // Sidebar categories const sidebarCategories = [ { id: "All", name: t.menu.allDishes || "All Dishes" }, ...menuCategories.map((cat) => ({ id: cat.id, name: cat.name })), ]; // Filtering logic const filteredCategories = useMemo(() => { return menuCategories .map((category) => { let items = category.items; // Sidebar filter if (activeCategory !== "All" && category.id !== activeCategory) { items = []; } // Search if (searchQuery.trim()) { const q = searchQuery.toLowerCase().trim(); items = items.filter( (item) => item.name.toLowerCase().includes(q) || (item.description && item.description.toLowerCase().includes(q)) ); } // Vegetarian if (showVegetarianOnly) { items = items.filter((item) => item.isVegetarian); } return { ...category, items }; }) .filter((category) => category.items.length > 0); }, [searchQuery, showVegetarianOnly, activeCategory]); const handleCategorySelect = (id: string) => { setActiveCategory(id); window.scrollTo({ top: 220, behavior: "smooth" }); }; // Mobile video auto-play on scroll pause (3s) useEffect(() => { const updateMobile = () => setIsMobile(window.innerWidth < 768); updateMobile(); window.addEventListener("resize", updateMobile); return () => window.removeEventListener("resize", updateMobile); }, []); const playMobileVideo = (id: string) => { document.querySelectorAll(".menu-card").forEach((card) => { if (card.dataset.id !== id) return; const media = card.querySelector(".relative.h-52"); if (!media) return; const img = media.querySelector("img"); const video = media.querySelector("video"); const gradient = media.querySelector(".absolute.inset-0.bg-gradient-to-b"); if (img) img.style.opacity = "0"; if (video) { video.style.opacity = "1"; video.play().catch(() => {}); } if (gradient) gradient.style.opacity = "0"; }); }; const pauseAllMobileVideos = () => { document.querySelectorAll(".menu-card").forEach((card) => { const media = card.querySelector(".relative.h-52"); if (!media) return; const img = media.querySelector("img"); const video = media.querySelector("video"); const gradient = media.querySelector(".absolute.inset-0.bg-gradient-to-b"); if (img) img.style.opacity = ""; if (video) { video.style.opacity = "0"; video.pause(); video.currentTime = 0; } if (gradient) gradient.style.opacity = ""; }); }; const findFocusedVideoItem = (): string | null => { const cards = document.querySelectorAll('.menu-card[data-has-video="true"]'); let bestId: string | null = null; let bestScore = 0; const vh = window.innerHeight; const viewportCenter = vh / 2; cards.forEach((card) => { const rect = card.getBoundingClientRect(); if (rect.bottom <= 0 || rect.top >= vh) return; const visibleTop = Math.max(rect.top, 0); const visibleBottom = Math.min(rect.bottom, vh); const visibleHeight = visibleBottom - visibleTop; const intersectionRatio = visibleHeight / rect.height; const cardCenter = rect.top + rect.height / 2; const distFromCenter = Math.abs(cardCenter - viewportCenter); const centerScore = Math.max(0, 1 - distFromCenter / (vh / 2)); const score = intersectionRatio * 0.6 + centerScore * 0.4; if (score > bestScore && score > 0.15) { bestScore = score; bestId = card.dataset.id || null; } }); return bestId; }; useEffect(() => { if (!isMobile) { pauseAllMobileVideos(); return; } let scrollTimeout: ReturnType | null = null; const onScrollOrTouch = () => { pauseAllMobileVideos(); if (scrollTimeout) clearTimeout(scrollTimeout); scrollTimeout = setTimeout(() => { const focusedId = findFocusedVideoItem(); if (focusedId) { playMobileVideo(focusedId); } }, 3000); }; window.addEventListener("scroll", onScrollOrTouch, { passive: true }); window.addEventListener("touchmove", onScrollOrTouch, { passive: true }); // Initial play after load on mobile (if not scrolling) const initialTimeout = setTimeout(() => { const firstFocused = findFocusedVideoItem(); if (firstFocused) { playMobileVideo(firstFocused); } }, 1500); return () => { window.removeEventListener("scroll", onScrollOrTouch); window.removeEventListener("touchmove", onScrollOrTouch); if (scrollTimeout) clearTimeout(scrollTimeout); clearTimeout(initialTimeout); }; }, [isMobile]); return (
{/* Page Header */}
AUTHENTIC • GENEROUS • ROYAL

{t.menu.title}

{t.menu.subtitle}

{/* Main Layout */}
{/* BEAUTIFUL SIDEBAR */}
EXPLORE OUR

Signature Categories

{/* Modern mobile-first category menu: horizontal scroller on phones/tablets, vertical sidebar on desktop */}
{sidebarCategories.map((cat) => { const isActive = activeCategory === cat.id; const itemCount = cat.id === "All" ? menuCategories.reduce((sum, c) => sum + c.items.length, 0) : menuCategories.find(c => c.id === cat.id)?.items.length || 0; return ( ); })}
{/* MAIN CONTENT */}
{/* Search + Vegetarian Filter */}
setSearchQuery(e.target.value)} className="w-full md:w-80 rounded-2xl border border-[#e5e1d7] bg-white px-5 py-3 text-sm placeholder:text-[#8A8478] focus:border-[#c99a2e] focus:ring-2 focus:ring-[#c99a2e]/20 transition-all" /> {(searchQuery || showVegetarianOnly || activeCategory !== "All") && ( )}
{/* Menu Items */} {filteredCategories.length === 0 ? (
{t.menu.noResults}
) : ( filteredCategories.map((category) => (
{category.name}
{category.items.length} {t.menu.dishes}
{category.items.map((item) => (
addToCart({ id: item.id, name: item.name, price: item.price, image: item.image })} > {/* Media - Restored Premium Video Hover + Poster Logic */} {item.video ? (
{ const video = e.currentTarget.querySelector("video"); if (video) video.play().catch(() => {}); }} onMouseLeave={(e) => { const video = e.currentTarget.querySelector("video"); if (video) { video.pause(); video.currentTime = 0; } }} onClick={() => addToCart({ id: item.id, name: item.name, price: item.price, image: item.image })} > {/* Static Poster (first frame) */} {item.name} { // Fallback poster logic const base = (item.video || item.image || "").replace(".mp4", "").replace(/-optimized/g, ""); const fallbacks = [ `/images/dishes/${base}-poster.jpg`, `/images/dishes/${base}-optimized-poster.jpg`, `/images/dishes/${item.image}`, ].filter(Boolean); let i = 0; const tryNext = () => { if (i < fallbacks.length) { (e.target as HTMLImageElement).src = fallbacks[i++]; } }; tryNext(); }} /> {/* Video on Hover - robust source selection with optimized fallbacks */}
) : ( /* Static Image for items without video */
addToCart({ id: item.id, name: item.name, price: item.price, image: item.image })} > {item.name}
)}

{item.name}

{item.price}
KR
{item.description && (

{(t as any).menuDescriptions?.[item.id] || item.description}

)}
{item.isVegetarian && ( VEGETARIAN )}
))}
)) )}
); }