/**
 * statusTokens — centralised signal-colour helper (F5DS-005 / F5A11Y-001).
 *
 * Problem: HealthScoreBreakdown, WinnersLosersTable, and CalendarView each
 * re-implemented their own score/severity → colour mapping using raw-palette
 * classes (amber-*, green-*, red-*) or base-shade signal classes that fail
 * WCAG AA for text. This single helper replaces all of them.
 *
 * All text and icon classes use the `-strong` shade (≥4.5:1 on white/dark
 * backgrounds). Background and border classes use the base / `-soft` shades
 * (graphic-element 3:1 threshold applies — they do not require -strong).
 *
 * Usage:
 *   const { text, bg, border } = scoreTokens(score);
 *   const { text, bg, border } = severityTokens('critical');
 */

export interface StatusTokens {
  /** WCAG-AA text colour class (use for text nodes and icons). */
  text: string;
  /** Soft background class (safe for badge backgrounds, tinted areas). */
  bg: string;
  /** Border/accent class (safe for decorative borders, side-bars). */
  border: string;
}

/**
 * Maps a 0–100 score to semantic token classes.
 * Mirrors the thresholds used in HealthScoreBreakdown and WinnersLosersTable.
 */
export function scoreTokens(score: number): StatusTokens {
  if (score >= 80) {
    return { text: 'text-success-strong', bg: 'bg-success-soft', border: 'border-success' };
  }
  if (score >= 40) {
    return { text: 'text-warning-strong', bg: 'bg-warning-soft', border: 'border-warning' };
  }
  return {
    text: 'text-destructive-strong',
    bg: 'bg-destructive-soft',
    border: 'border-destructive',
  };
}

export type SeverityLevel = 'success' | 'info' | 'warning' | 'critical' | 'neutral';

/**
 * Maps a named severity level to semantic token classes.
 * Covers losers/winners severity labels, calendar status, connection health, etc.
 */
export function severityTokens(level: SeverityLevel): StatusTokens {
  switch (level) {
    case 'success':
      return { text: 'text-success-strong', bg: 'bg-success-soft', border: 'border-success' };
    case 'info':
      return { text: 'text-info-strong', bg: 'bg-info/10', border: 'border-info' };
    case 'warning':
      return { text: 'text-warning-strong', bg: 'bg-warning-soft', border: 'border-warning' };
    case 'critical':
      return {
        text: 'text-destructive-strong',
        bg: 'bg-destructive-soft',
        border: 'border-destructive',
      };
    case 'neutral':
    default:
      return { text: 'text-muted-foreground', bg: 'bg-muted', border: 'border-border' };
  }
}
