import { describe, it, expect, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import ScoresPanel from '@/components/patient/ScoresPanel.vue'
import { useScoringStore } from '@/stores/scoring'

describe('ScoresPanel', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
    const store = useScoringStore()
    store.$patch({
      news2: { totalScore: 5, riskLevel: 'Medium' },
      gcs: { eyeScore: 4, verbalScore: 5, motorScore: 6, totalScore: 15 },
      sofa: { totalScore: 4, deltaFromBaseline: 0, respiratoryScore: 1, coagulationScore: 0, liverScore: 0, cardiovascularScore: 1, cnsScore: 1, renalScore: 1 },
      qsofa: { activeCriteria: 2 },
    })
  })

  it('showsGcsSection', () => {
    const wrapper = mount(ScoresPanel)
    expect(wrapper.text()).toContain('GCS')
    expect(wrapper.text()).toContain('15/15')
    expect(wrapper.text()).toContain('E4 V5 M6')
  })

  it('showsSofaSection', () => {
    const wrapper = mount(ScoresPanel)
    expect(wrapper.text()).toContain('SOFA')
    expect(wrapper.text()).toContain('4/24')
  })

  it('noSirsReference', () => {
    const wrapper = mount(ScoresPanel)
    expect(wrapper.text().toUpperCase()).not.toContain('SIRS')
  })

  it('qsofaLabeledAsScreen', () => {
    const wrapper = mount(ScoresPanel)
    expect(wrapper.text()).toContain('qSOFA Screen')
    expect(wrapper.text()).toContain('Bedside screening')
  })

  it('sofaOrganBadgesUseResponsiveGrid', () => {
    const wrapper = mount(ScoresPanel)
    const grid = wrapper.find('.grid.grid-cols-2')
    expect(grid.exists()).toBe(true)
    expect(grid.classes()).toContain('sm:flex')
  })
})