"use client"; import { ChevronDown, ChevronLeft } from "lucide-react"; import Link from "next/link"; import { useEffect, useMemo, useState } from "react"; import { categoryPath, fetchProductCategories, getLevelTwoProductCategories, type ProductCategory, } from "../lib/meshkee"; type ActivePage = "home" | "products" | "about" | "contact"; const navigationItems: { label: string; href: string; key?: ActivePage; }[] = [ { label: "صفحه اصلی", href: "/", key: "home" }, { label: "خدمات", href: "/#services" }, { label: "اخبار", href: "/#news" }, { label: "درباره ما", href: "/about-us", key: "about" }, { label: "تماس با ما", href: "/contact-us", key: "contact" }, ]; export default function HeaderNavigation({ active, mobileOpen, onNavigate, }: { active?: ActivePage; mobileOpen: boolean; onNavigate?: () => void; }) { const [categories, setCategories] = useState([]); useEffect(() => { const controller = new AbortController(); fetchProductCategories(controller.signal) .then(setCategories) .catch(() => { // Keep the all-products link when categories cannot be loaded. }); return () => controller.abort(); }, []); const levelTwoCategories = useMemo( () => getLevelTwoProductCategories(categories), [categories], ); const renderCategoryLinks = () => ( <> همه ماشین‌آلات ALL PRODUCTS {levelTwoCategories.map((category) => ( {category.nameFa || category.name} {category.name} ))} ); return ( <> {mobileOpen && ( )} ); }