/**
 * Reputation Blueprint report theme.
 *
 * Infographic-style color palette, typography scale, and helper
 * functions for the premium report product.
 */

// =============================================================================
// Score Bands — health_score (0-100)
// =============================================================================

export type ScoreBand = 'excellent' | 'good' | 'fair' | 'poor' | 'critical';

const SCORE_BANDS: { min: number; band: ScoreBand; color: string; label: string }[] = [
  { min: 90, band: 'excellent', color: '#059669', label: 'Excellent' },
  { min: 75, band: 'good',      color: '#22c55e', label: 'Good' },
  { min: 60, band: 'fair',      color: '#f59e0b', label: 'Fair' },
  { min: 40, band: 'poor',      color: '#f97316', label: 'Poor' },
  { min: 0,  band: 'critical',  color: '#ef4444', label: 'Critical' },
];

export function getScoreBand(score: number): ScoreBand {
  for (const { min, band } of SCORE_BANDS) {
    if (score >= min) return band;
  }
  return 'critical';
}

export function getScoreColor(score: number): string {
  for (const { min, color } of SCORE_BANDS) {
    if (score >= min) return color;
  }
  return '#ef4444';
}

const SCORE_LABELS: Record<string, Record<string, string>> = {
  en: { excellent: 'Excellent', good: 'Good', fair: 'Fair', poor: 'Poor', critical: 'Critical' },
  es: { excellent: 'Excelente', good: 'Bueno', fair: 'Regular', poor: 'Malo', critical: 'Crítico' },
};

export function getScoreLabel(score: number, locale: string = 'en'): string {
  const band = getScoreBand(score);
  return SCORE_LABELS[locale]?.[band] ?? SCORE_LABELS.en?.[band] ?? band;
}

// =============================================================================
// Domain Colors — URT domains (O, P, J, E, V, M)
// =============================================================================

const DOMAIN_COLORS: Record<string, string> = {
  O: '#3b82f6', // blue  — Output Quality
  P: '#22c55e', // green — People & Service
  J: '#f59e0b', // amber — Journey & Process
  E: '#8b5cf6', // purple — Environment
  V: '#f43f5e', // rose  — Value
  M: '#6b7280', // gray  — Meta / Other
};

export function getDomainColor(domain: string): string {
  return DOMAIN_COLORS[domain.charAt(0).toUpperCase()] || DOMAIN_COLORS.M || '#6b7280';
}

// =============================================================================
// Risk Colors — indicator color field
// =============================================================================

const RISK_COLORS: Record<string, string> = {
  green: '#059669',
  yellow: '#f59e0b',
  red: '#ef4444',
};

export function getRiskColor(color: string): string {
  return RISK_COLORS[color] || RISK_COLORS.yellow || '#f59e0b';
}

// =============================================================================
// Valence Colors
// =============================================================================

const VALENCE_COLORS: Record<string, string> = {
  positive: '#22c55e',
  negative: '#ef4444',
  neutral: '#9ca3af',
  mixed: '#f59e0b',
};

export function getValenceColor(valence: string): string {
  const key = valence.toLowerCase().replace('v+', 'positive').replace('v-', 'negative').replace('v0', 'neutral').replace('v±', 'mixed');
  return VALENCE_COLORS[key] || VALENCE_COLORS.neutral || '#9ca3af';
}

// =============================================================================
// Effort / Impact Colors (action matrix)
// =============================================================================

const EFFORT_COLORS: Record<string, string> = {
  low: '#22c55e',
  medium: '#f59e0b',
  high: '#ef4444',
};

export function getEffortColor(effort: string): string {
  return EFFORT_COLORS[effort] || EFFORT_COLORS.medium || '#f59e0b';
}

const QUADRANT_COLORS: Record<string, { bg: string; text: string; border: string }> = {
  quick_win:     { bg: '#ecfdf5', text: '#059669', border: '#a7f3d0' },
  major_project: { bg: '#eff6ff', text: '#2563eb', border: '#bfdbfe' },
  fill_in:       { bg: '#fefce8', text: '#ca8a04', border: '#fef08a' },
  deprioritize:  { bg: '#f3f4f6', text: '#6b7280', border: '#d1d5db' },
};

export function getQuadrantStyle(quadrant: string) {
  return QUADRANT_COLORS[quadrant] || QUADRANT_COLORS.major_project;
}

// =============================================================================
// Typography Scale
// =============================================================================

export const typography = {
  displayXl: { size: '52px', weight: 700, lineHeight: 1.1 },
  displayLg: { size: '32px', weight: 700, lineHeight: 1.15 },
  displayMd: { size: '26px', weight: 600, lineHeight: 1.2 },
  headingLg: { size: '20px', weight: 600, lineHeight: 1.3 },
  headingMd: { size: '17px', weight: 600, lineHeight: 1.35 },
  bodyLg:    { size: '16px', weight: 400, lineHeight: 1.6 },
  bodyMd:    { size: '14px', weight: 400, lineHeight: 1.6 },
  bodySm:    { size: '13px', weight: 400, lineHeight: 1.5 },
  caption:   { size: '11px', weight: 400, lineHeight: 1.4 },
} as const;

// =============================================================================
// Section Accent Colors (left border + header tint)
// =============================================================================

export const sectionColors = {
  cover:             '#1E293B',
  executive:         '#4285F4',
  ratingDashboard:   '#F59E0B',
  themeAnalysis:     '#6366F1',
  domainPerformance: '#8B5CF6',
  criticalIssues:    '#EA4335',
  strengths:         '#34A853',
  actionPlan:        '#4285F4',
  tracking:          '#0EA5E9',
} as const;

// =============================================================================
// Momentum Indicator
// =============================================================================

const MOMENTUM_STYLES: Record<string, { color: string; label: string }> = {
  improving: { color: '#22c55e', label: 'Improving' },
  declining: { color: '#ef4444', label: 'Declining' },
  stable:    { color: '#6b7280', label: 'Stable' },
};

export function getMomentumStyle(momentum: string) {
  return MOMENTUM_STYLES[momentum] || MOMENTUM_STYLES.stable;
}

// =============================================================================
// Chart Palette (for generic series)
// =============================================================================

export const chartPalette = [
  '#3b82f6', // blue
  '#22c55e', // green
  '#f59e0b', // amber
  '#8b5cf6', // purple
  '#f43f5e', // rose
  '#0ea5e9', // sky
  '#f97316', // orange
  '#6b7280', // gray
];
