export const CATEGORIES = [
  "Official Store",
  "Appliances",
  "Phones & Tablets",
  "Health & Beauty",
  "Electronics",
  "Home & Office",
  "Fashion",
  "Supermarket",
  "Computing",
  "Baby Products",
  "Gaming",
  "Other categories",
] as const;

export type CategoryName = (typeof CATEGORIES)[number];

export function slugify(name: string) {
  return name
    .toLowerCase()
    .replace(/&/g, "and")
    .replace(/[^a-z0-9]+/g, "-")
    .replace(/(^-|-$)/g, "");
}

export function findCategoryBySlug(slug: string): CategoryName | undefined {
  return CATEGORIES.find((c) => slugify(c) === slug);
}

// Map a category to related seed/vendor product categories so pages aren't empty.
const RELATED: Record<string, string[]> = {
  "Official Store": ["Phones & Tablets", "Electronics", "Computing"],
  "Appliances": ["Appliances"],
  "Phones & Tablets": ["Phones & Tablets", "Mobile Accessories"],
  "Health & Beauty": ["Health & Beauty"],
  "Electronics": ["Electronics"],
  "Home & Office": ["Home & Office", "Appliances"],
  "Fashion": ["Fashion"],
  "Supermarket": ["Groceries", "Supermarket"],
  "Computing": ["Computing", "Mobile Accessories"],
  "Baby Products": ["Baby Products"],
  "Gaming": ["Gaming", "Electronics"],
  "Other categories": [],
};

export function relatedCategories(name: string): string[] {
  return RELATED[name] ?? [name];
}
