/**
 * The monochrome chart palette.
 *
 * recharts writes these straight onto SVG presentation attributes, where
 * `var()` resolves natively — so colours stay CSS custom properties end to end.
 * No getComputedStyle, no MutationObserver, no JS colour plumbing.
 *
 * THE ENCODING PROBLEM
 * Five gray steps carry about three distinguishable series by luminance alone.
 * Rather than reach for hue the moment a fourth series appears, the primitives
 * encode extra dimensions non-chromatically — dash pattern, stroke width, and
 * hatch fill. Colour stays reserved for meaning.
 */

/** Ordered series ramp, lightest first — series 0 is the most important. */
export const SERIES = [
  'var(--color-data-gray-5)', // #E4E4E7
  'var(--color-data-gray-4)', // #A1A1AA
  'var(--color-data-gray-3)', // #71717A
  'var(--color-data-gray-2)', // #52525B
  'var(--color-data-gray-1)', // #3F3F46
] as const;

export const CHART = {
  series: SERIES,
  seriesAt: (i: number) => SERIES[i % SERIES.length],
  grid: 'var(--color-border)',
  axis: 'var(--color-text-secondary)',
  axisLine: 'var(--color-border-emphasized)',
  cursor: 'var(--color-overlay-hover)',
  reference: 'var(--color-text-disabled)',
  /**
   * Semantic colour. Used ONLY where the colour itself carries the meaning:
   * a delta against target, a threshold breach, an expiry warning. Never to
   * tell two ordinary series apart.
   */
  positive: 'var(--color-success)',
  negative: 'var(--color-error)',
  attention: 'var(--color-warning)',
} as const;

/** The non-chromatic channel. */
export type SeriesEncoding = 'solid' | 'dashed' | 'dotted' | 'hatch';

const DASH: Record<SeriesEncoding, string | undefined> = {
  solid: undefined,
  dashed: '6 3',
  dotted: '2 3',
  hatch: undefined,
};

export function dashFor(encoding: SeriesEncoding = 'solid') {
  return DASH[encoding];
}

/**
 * Series beyond the second get progressively thinner as well as darker, so
 * they read as background context rather than competing for attention.
 */
export function strokeWidthFor(index: number) {
  return index === 0 ? 2 : index === 1 ? 1.75 : 1.5;
}

/** Default encoding per series position, when the caller does not specify one. */
export function defaultEncoding(index: number): SeriesEncoding {
  return index === 0 ? 'solid' : index === 1 ? 'dashed' : 'dotted';
}
