import type { ContrastPair, ColorTokenKey } from './types'

const SURFACES: readonly ColorTokenKey[] = ['bg', 'surface', 'surface-raised']
const INTENTS: readonly ColorTokenKey[] = ['success', 'warning', 'danger', 'info']
const INTENT_FG: Record<string, ColorTokenKey> = {
  success: 'success-fg', warning: 'warning-fg', danger: 'danger-fg', info: 'info-fg',
}

function build(): ContrastPair[] {
  const pairs: ContrastPair[] = []
  // body text on every surface (4.5) — fg + fg-muted are both body copy:
  for (const fg of ['fg', 'fg-muted'] as ColorTokenKey[])
    for (const bg of SURFACES) pairs.push({ fg, bg, level: 'text' })
  // de-emphasized text on every surface (3.0 — hint/secondary, never primary copy):
  for (const bg of SURFACES) pairs.push({ fg: 'fg-subtle', bg, level: 'ui' })
  // text/icon on the accent fill (4.5):
  pairs.push({ fg: 'accent-fg', bg: 'accent', level: 'text' })
  // text/icon on each intent FILL (4.5):
  for (const intent of INTENTS) pairs.push({ fg: INTENT_FG[intent]!, bg: intent, level: 'text' })
  // intent colors used as TEXT on base surfaces (4.5):
  for (const fg of INTENTS) for (const bg of SURFACES) pairs.push({ fg, bg, level: 'text' })
  // non-text UI boundaries / fills (3.0, WCAG 1.4.11):
  for (const bg of SURFACES) pairs.push({ fg: 'border-strong', bg, level: 'ui' })
  for (const bg of SURFACES) pairs.push({ fg: 'accent', bg, level: 'ui' })
  for (const fg of INTENTS) for (const bg of SURFACES) pairs.push({ fg, bg, level: 'ui' })
  return pairs
}

/** Frozen declared fg/bg set the design system renders together. validateContrast iterates THIS. */
export const CONTRAST_PAIRS: readonly ContrastPair[] = Object.freeze(build())
