import { describe, it, expect } from 'vitest'
import { CONTRAST_PAIRS } from './contrast-pairs'
import { COLOR_TOKEN_KEYS } from './keys'

describe('CONTRAST_PAIRS', () => {
  it('is frozen and non-empty', () => {
    expect(Object.isFrozen(CONTRAST_PAIRS)).toBe(true)
    expect(CONTRAST_PAIRS.length).toBeGreaterThan(0)
  })
  it('every fg/bg references a real ui-tokens color key', () => {
    const keys = new Set<string>(COLOR_TOKEN_KEYS as readonly string[])
    for (const p of CONTRAST_PAIRS) {
      expect(keys.has(p.fg)).toBe(true)
      expect(keys.has(p.bg)).toBe(true)
      expect(p.level === 'text' || p.level === 'ui').toBe(true)
    }
  })
  it('declares the load-bearing pairs from spec §2a', () => {
    const has = (fg: string, bg: string, level: string) =>
      CONTRAST_PAIRS.some((p) => p.fg === fg && p.bg === bg && p.level === level)
    expect(has('fg', 'bg', 'text')).toBe(true)
    expect(has('fg-subtle', 'surface', 'ui')).toBe(true)          // de-emphasized hint = ui/3.0
    expect(has('accent-fg', 'accent', 'text')).toBe(true)         // text on accent fill
    expect(has('success-fg', 'success', 'text')).toBe(true)       // text on intent fill
    expect(has('danger', 'bg', 'text')).toBe(true)                // intent-as-text
    expect(has('border-strong', 'bg', 'ui')).toBe(true)           // non-text UI boundary
    expect(has('info', 'surface', 'ui')).toBe(true)               // intent fill as UI element
  })
  it('contains NO not-checked decorative pairs (border subtle, surface-vs-surface)', () => {
    expect(CONTRAST_PAIRS.some((p) => p.fg === 'border')).toBe(false)
    expect(CONTRAST_PAIRS.some((p) => p.fg === 'surface' && p.bg === 'surface')).toBe(false)
  })
})
