// Preset palette for per-environment color indicator. Mirrors the backend
// EnvironmentColor enum. Add/remove entries here AND in:
//   - backend V*__add_environment_color.sql CHECK constraint
//   - cameleer-server-core/.../EnvironmentColor.java VALUES set
//   - ui/src/styles/env-colors.css (token definitions)

export const ENV_COLORS = [
  'slate',
  'red',
  'amber',
  'green',
  'teal',
  'blue',
  'purple',
  'pink',
] as const;

export type EnvColor = (typeof ENV_COLORS)[number];
export const DEFAULT_ENV_COLOR: EnvColor = 'slate';

export function isEnvColor(v: string | null | undefined): v is EnvColor {
  return typeof v === 'string' && (ENV_COLORS as readonly string[]).includes(v);
}

// Safe for any string input — unknown/missing values resolve to the default
// token. Use this whenever rendering an env's color; never concat directly.
export function envColorVar(color: string | null | undefined): string {
  return `var(--env-color-${isEnvColor(color) ? color : DEFAULT_ENV_COLOR})`;
}
