import type { Locale } from "next-intl";

export const BLOG_CATEGORIES = [
  { id: "responsible", slug: { en: "responsible", fr: "responsable" } },
  { id: "sourcing", slug: { en: "sourcing", fr: "sourcing" } },
  { id: "process", slug: { en: "process", fr: "procedes" } },
  { id: "design", slug: { en: "design", fr: "design" } },
  { id: "guides", slug: { en: "guides", fr: "guides" } },
  { id: "news", slug: { en: "news", fr: "infos" } },
] as const;

export type CategoryId = (typeof BLOG_CATEGORIES)[number]["id"];

export const CATEGORY_IDS = BLOG_CATEGORIES.map((c) => c.id) as readonly CategoryId[];

export function categorySlug(id: CategoryId, locale: Locale): string {
  const cat = BLOG_CATEGORIES.find((c) => c.id === id);
  if (!cat) throw new Error(`[blog] unknown category id: ${id}`);
  return cat.slug[locale as "en" | "fr"];
}

export function categoryIdFromSlug(slug: string, locale: Locale): CategoryId | null {
  const cat = BLOG_CATEGORIES.find((c) => c.slug[locale as "en" | "fr"] === slug);
  return cat ? cat.id : null;
}
