Files
meezi/web/dashboard/src/lib/menu-item-image.ts
T

53 lines
1.4 KiB
TypeScript
Raw Normal View History

import { Coffee, CupSoda, UtensilsCrossed, type LucideIcon } from "lucide-react";
import { resolveMediaUrl } from "@/lib/api/client";
export type MenuItemVisualKind = "food" | "drink";
const DRINK_CATEGORY_IDS = new Set(["cat_demo_drinks", "cat_demo_cold"]);
/** Latin keywords; Persian/Arabic category names come from API `categoryName`. */
const DRINK_HINTS = [
"drink",
"cold",
"hot",
"coffee",
"tea",
"juice",
"smoothie",
"beverage",
"bar",
"espresso",
"latte",
];
export function inferMenuItemKind(
categoryId: string,
categoryName?: string
): MenuItemVisualKind {
if (DRINK_CATEGORY_IDS.has(categoryId)) return "drink";
const haystack = `${categoryId} ${categoryName ?? ""}`.toLowerCase();
if (DRINK_HINTS.some((h) => haystack.includes(h))) return "drink";
return "food";
}
export function getMenuItemImageSrc(imageUrl?: string | null): string | undefined {
return resolveMediaUrl(imageUrl);
}
export function menuItemPlaceholderIcon(kind: MenuItemVisualKind): LucideIcon {
return kind === "drink" ? CupSoda : UtensilsCrossed;
}
/** Larger hero-style icon for sidebar preview */
export function menuItemPlaceholderHeroIcon(kind: MenuItemVisualKind): LucideIcon {
return kind === "drink" ? Coffee : UtensilsCrossed;
}
export function buildCategoryNameMap(
categories: { id: string; name: string }[]
): Map<string, string> {
return new Map(categories.map((c) => [c.id, c.name]));
}