"use client"; import React, { useEffect, useRef } from "react"; import { MenuCategory } from "@/data/menu"; interface CategoryNavProps { categories: MenuCategory[]; activeCategoryId: string; icons: Record; } export function CategoryNav({ categories, activeCategoryId, icons }: CategoryNavProps) { const containerRef = useRef(null); useEffect(() => { if (!activeCategoryId || !containerRef.current) return; const el = containerRef.current.querySelector( `[data-id="${activeCategoryId}"]` ) as HTMLElement | null; el?.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center" }); }, [activeCategoryId]); const scrollTo = (id: string) => { const el = document.getElementById(id); if (!el) return; const y = el.getBoundingClientRect().top + window.scrollY - 72; window.scrollTo({ top: y, behavior: "smooth" }); }; return (
{categories.map((cat) => { const active = cat.id === activeCategoryId; return ( ); })}
); }