import { describe, expect, it } from 'vitest'
import {
  getScoreLevel,
  scoreToColor,
  scoreToTextColor,
  scoreColors,
  getScoreBgClass,
  getScoreTextClass,
  getScoreBorderClass,
  getScoreBgColor,
  getScoreTextColor,
  getScoreHexColor,
  getScoreColorClasses,
} from '../score'

describe('getScoreLevel', () => {
  it('returns critical for 0', () => {
    expect(getScoreLevel(0)).toBe('critical')
  })

  it('returns critical for 39', () => {
    expect(getScoreLevel(39)).toBe('critical')
  })

  it('returns concerning for 40', () => {
    expect(getScoreLevel(40)).toBe('concerning')
  })

  it('returns concerning for 59', () => {
    expect(getScoreLevel(59)).toBe('concerning')
  })

  it('returns warning for 60', () => {
    expect(getScoreLevel(60)).toBe('warning')
  })

  it('returns warning for 79', () => {
    expect(getScoreLevel(79)).toBe('warning')
  })

  it('returns good for 80', () => {
    expect(getScoreLevel(80)).toBe('good')
  })

  it('returns good for 100', () => {
    expect(getScoreLevel(100)).toBe('good')
  })

  it('returns critical for negative values', () => {
    expect(getScoreLevel(-1)).toBe('critical')
    expect(getScoreLevel(-100)).toBe('critical')
  })

  it('returns good for values above 100', () => {
    expect(getScoreLevel(101)).toBe('good')
    expect(getScoreLevel(999)).toBe('good')
  })
})

describe('scoreColors', () => {
  it('has entries for all four levels', () => {
    expect(scoreColors.good.bg).toBe('bg-score-good')
    expect(scoreColors.good.text).toBe('text-score-good')
    expect(scoreColors.good.hex).toBe('var(--color-score-good)')

    expect(scoreColors.warning.bg).toBe('bg-score-warning')
    expect(scoreColors.concerning.bg).toBe('bg-score-concerning')
    expect(scoreColors.critical.bg).toBe('bg-score-critical')
  })
})

describe('scoreToColor', () => {
  it('returns correct CSS var for critical score (0)', () => {
    expect(scoreToColor(0)).toBe('var(--color-score-critical)')
  })

  it('returns correct CSS var for concerning score (40)', () => {
    expect(scoreToColor(40)).toBe('var(--color-score-concerning)')
  })

  it('returns correct CSS var for warning score (60)', () => {
    expect(scoreToColor(60)).toBe('var(--color-score-warning)')
  })

  it('returns correct CSS var for good score (80)', () => {
    expect(scoreToColor(80)).toBe('var(--color-score-good)')
  })

  it('returns correct CSS var for boundary value 39', () => {
    expect(scoreToColor(39)).toBe('var(--color-score-critical)')
  })

  it('returns correct CSS var for boundary value 59', () => {
    expect(scoreToColor(59)).toBe('var(--color-score-concerning)')
  })

  it('returns correct CSS var for boundary value 79', () => {
    expect(scoreToColor(79)).toBe('var(--color-score-warning)')
  })

  it('returns correct CSS var for 100', () => {
    expect(scoreToColor(100)).toBe('var(--color-score-good)')
  })

  it('handles negative values', () => {
    expect(scoreToColor(-5)).toBe('var(--color-score-critical)')
  })

  it('handles values above 100', () => {
    expect(scoreToColor(150)).toBe('var(--color-score-good)')
  })
})

describe('scoreToTextColor', () => {
  it('returns same result as scoreToColor for critical score', () => {
    expect(scoreToTextColor(0)).toBe(scoreToColor(0))
  })

  it('returns same result as scoreToColor for concerning score', () => {
    expect(scoreToTextColor(40)).toBe(scoreToColor(40))
  })

  it('returns same result as scoreToColor for warning score', () => {
    expect(scoreToTextColor(60)).toBe(scoreToColor(60))
  })

  it('returns same result as scoreToColor for good score', () => {
    expect(scoreToTextColor(80)).toBe(scoreToColor(80))
  })

  it('returns correct CSS var string for boundary values', () => {
    expect(scoreToTextColor(39)).toBe('var(--color-score-critical)')
    expect(scoreToTextColor(59)).toBe('var(--color-score-concerning)')
    expect(scoreToTextColor(79)).toBe('var(--color-score-warning)')
    expect(scoreToTextColor(100)).toBe('var(--color-score-good)')
  })
})

describe('getScoreBgClass', () => {
  it('returns bg-score-critical for low scores', () => {
    expect(getScoreBgClass(10)).toBe('bg-score-critical')
  })

  it('returns bg-score-concerning for mid-low scores', () => {
    expect(getScoreBgClass(45)).toBe('bg-score-concerning')
  })

  it('returns bg-score-warning for mid-high scores', () => {
    expect(getScoreBgClass(65)).toBe('bg-score-warning')
  })

  it('returns bg-score-good for high scores', () => {
    expect(getScoreBgClass(90)).toBe('bg-score-good')
  })
})

describe('getScoreTextClass', () => {
  it('returns text-score-critical for low scores', () => {
    expect(getScoreTextClass(10)).toBe('text-score-critical')
  })

  it('returns text-score-good for high scores', () => {
    expect(getScoreTextClass(90)).toBe('text-score-good')
  })
})

describe('getScoreBorderClass', () => {
  it('returns border-score-critical for low scores', () => {
    expect(getScoreBorderClass(10)).toBe('border-score-critical')
  })

  it('returns border-score-good for high scores', () => {
    expect(getScoreBorderClass(90)).toBe('border-score-good')
  })
})

describe('getScoreBgColor', () => {
  it('returns Tailwind bg class from scoreColors map', () => {
    expect(getScoreBgColor(90)).toBe('bg-score-good')
    expect(getScoreBgColor(65)).toBe('bg-score-warning')
    expect(getScoreBgColor(45)).toBe('bg-score-concerning')
    expect(getScoreBgColor(10)).toBe('bg-score-critical')
  })
})

describe('getScoreTextColor', () => {
  it('returns Tailwind text class from scoreColors map', () => {
    expect(getScoreTextColor(90)).toBe('text-score-good')
    expect(getScoreTextColor(65)).toBe('text-score-warning')
    expect(getScoreTextColor(45)).toBe('text-score-concerning')
    expect(getScoreTextColor(10)).toBe('text-score-critical')
  })
})

describe('getScoreHexColor', () => {
  it('returns CSS variable reference from scoreColors map', () => {
    expect(getScoreHexColor(90)).toBe('var(--color-score-good)')
    expect(getScoreHexColor(65)).toBe('var(--color-score-warning)')
    expect(getScoreHexColor(45)).toBe('var(--color-score-concerning)')
    expect(getScoreHexColor(10)).toBe('var(--color-score-critical)')
  })
})

describe('getScoreColorClasses', () => {
  it('returns composite classes for good score', () => {
    const classes = getScoreColorClasses(90)
    expect(classes.text).toBe('text-score-good')
    expect(classes.bg).toBe('bg-score-good/10')
    expect(classes.border).toBe('border-score-good/20')
  })

  it('returns composite classes for warning score', () => {
    const classes = getScoreColorClasses(65)
    expect(classes.text).toBe('text-score-warning')
    expect(classes.bg).toBe('bg-score-warning/10')
    expect(classes.border).toBe('border-score-warning/20')
  })

  it('returns composite classes for concerning score', () => {
    const classes = getScoreColorClasses(45)
    expect(classes.text).toBe('text-score-concerning')
    expect(classes.bg).toBe('bg-score-concerning/10')
    expect(classes.border).toBe('border-score-concerning/20')
  })

  it('returns composite classes for critical score', () => {
    const classes = getScoreColorClasses(10)
    expect(classes.text).toBe('text-score-critical')
    expect(classes.bg).toBe('bg-score-critical/10')
    expect(classes.border).toBe('border-score-critical/20')
  })
})
