export const REGULAR_CATEGORIES = new Set([
  "rent", "utilities", "insurance", "subscriptions",
  "groceries", "dining", "transport", "fuel",
  "health", "personal_care", "government", "charity", "pets",
] as const);

export const CATEGORIES = [
  "groceries",
  "dining",
  "transport",
  "fuel",
  "shopping",
  "utilities",
  "entertainment",
  "travel",
  "health",
  "insurance",
  "subscriptions",
  "cash_advance",
  "government",
  "education",
  "rent",
  "home_goods",
  "home_maintenance",
  "transfers",
  "income",
  "investment",
  "loan_interest",
  "personal_care",
  "pets",
  "gifts",
  "charity",
  "fees",
  "other",
] as const;

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

// Tolerates null/undefined: an uncategorised transaction must never be able to
// crash a page that renders its category.
export function formatCategory(cat: string | null | undefined): string {
  if (!cat) return "Uncategorised";
  return cat
    .split("_")
    .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
    .join(" ");
}
