const HUES = ["teal", "amber", "rust", "slate", "olive"] as const;
export type Hue = (typeof HUES)[number];

export function categorySlug(category: string): string {
  return category
    .normalize("NFD")
    .replace(/[̀-ͯ]/g, "") // klemtoontekens eraf (bv. e-acute -> e)
    .toLowerCase()
    .replace(/[^a-z0-9]+/g, "-")
    .replace(/(^-|-$)/g, "");
}

// Deterministisch: dezelfde categorie krijgt overal (homepage, categorieen-pagina,
// reviewpagina) dezelfde kleur, zonder dat je 'm per review handmatig hoeft te kiezen.
export function categoryHue(category: string): Hue {
  const slug = categorySlug(category);
  let hash = 0;
  for (let i = 0; i < slug.length; i++) {
    hash = (hash * 31 + slug.charCodeAt(i)) | 0;
  }
  return HUES[Math.abs(hash) % HUES.length];
}
