// @vitest-environment node
import { describe, it, expect, vi, afterEach } from 'vitest'
import { daysUntil, useSeasonCountdown } from './useSeasonCountdown'

describe('daysUntil', () => {
  afterEach(() => {
    vi.useRealTimers()
  })

  it('returns a positive count for a future date', () => {
    vi.useFakeTimers()
    vi.setSystemTime(new Date('2026-08-05T12:00:00'))
    expect(daysUntil('2026-08-10')).toBe(5)
  })

  it('returns 0 for today', () => {
    vi.useFakeTimers()
    vi.setSystemTime(new Date('2026-08-10T18:30:00'))
    expect(daysUntil('2026-08-10')).toBe(0)
  })

  it('returns a negative count for a past date', () => {
    vi.useFakeTimers()
    vi.setSystemTime(new Date('2026-08-15T12:00:00'))
    expect(daysUntil('2026-08-10')).toBe(-5)
  })
})

describe('useSeasonCountdown', () => {
  afterEach(() => {
    vi.useRealTimers()
  })

  it('shows the "kicks off in" prefix and day count before the season starts', () => {
    vi.useFakeTimers()
    vi.setSystemTime(new Date('2026-08-05T12:00:00'))
    const { days, heroCountdownPrefix, heroCountdownBold } = useSeasonCountdown()
    expect(days).toBe(5)
    expect(heroCountdownPrefix).toBe('Season 6 kicks off in')
    expect(heroCountdownBold).toBe('5 days')
  })

  it('reports "1 day" without pluralizing', () => {
    vi.useFakeTimers()
    vi.setSystemTime(new Date('2026-08-09T12:00:00'))
    const { heroCountdownBold } = useSeasonCountdown()
    expect(heroCountdownBold).toBe('1 day')
  })

  it('shows the "kicks off today" message on the start date', () => {
    vi.useFakeTimers()
    vi.setSystemTime(new Date('2026-08-10T09:00:00'))
    const { days, heroCountdownPrefix, heroCountdownBold } = useSeasonCountdown()
    expect(days).toBe(0)
    expect(heroCountdownPrefix).toBe('')
    expect(heroCountdownBold).toBe('Season 6 kicks off today')
  })

  it('shows the "underway" message after the season starts', () => {
    vi.useFakeTimers()
    vi.setSystemTime(new Date('2026-08-15T09:00:00'))
    const { days, heroCountdownPrefix, heroCountdownBold } = useSeasonCountdown()
    expect(days).toBeLessThan(0)
    expect(heroCountdownPrefix).toBe('')
    expect(heroCountdownBold).toBe('Season 6 is underway')
  })
})
