/**
 * Badge colouring for the member tables.
 *
 * Neutral/positive states ride the promo accent (Mantine's primary is remapped
 * to it by the theme shell) so the member pages recolour with the rest of the
 * console. Only genuinely negative states break out into red/orange — those
 * carry meaning that must survive any accent choice.
 */

export type BadgeTone = {
  color?: string;
  variant: "light" | "filled";
};

const NEGATIVE = ["cancelled", "terminated", "expired", "deleted", "failure"];
const WARNING = ["suspended", "hold", "pending", "on hold"];

export const accountStatusTone = (status?: string | null): BadgeTone => {
  const value = status?.toLowerCase().trim() ?? "";
  if (NEGATIVE.some((token) => value.includes(token))) {
    return { color: "red", variant: "light" };
  }
  if (WARNING.some((token) => value.includes(token))) {
    return { color: "orange", variant: "light" };
  }
  // Accent-driven: no explicit colour means Mantine primary, which the theme
  // shell points at the chosen accent.
  return { variant: "light" };
};

export const recordStateTone = (isActive?: boolean | null): BadgeTone =>
  isActive ? { variant: "light" } : { color: "gray", variant: "light" };

export const outcomeTone = (status?: string | null): BadgeTone =>
  status?.toUpperCase() === "SUCCESS"
    ? { variant: "light" }
    : { color: "red", variant: "light" };

/** Booking entity types reuse the donut's role colours. */
export const bookingRole = (entityType?: string | null) => {
  const value = entityType?.toUpperCase() ?? "";
  if (value.includes("RCI") || value.includes("EXTERNAL")) return "curated";
  return "internal";
};
