import { getCategories, type ApiCategory } from "./api"; import { parentCategories } from "./data"; import { categoryHref } from "./paths"; export type MenuCategory = { name: string; href: string; children: { name: string; href: string }[]; }; function hrefForSlug(categories: ApiCategory[], slug: string) { const match = categories.find((category) => category.slug === slug); return match ? categoryHref(match) : `/products/${slug}`; } export async function getMenuCategories(): Promise { const categories = await getCategories(); return parentCategories.map((parent) => ({ name: parent.name, href: hrefForSlug(categories, parent.slug), children: parent.children.map((child) => ({ name: child.name, href: hrefForSlug(categories, child.slug), })), })); }