import { describe, it, expect, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import AlertReasoning from '@/components/alerts/AlertReasoning.vue'

const sepsisAlert = {
  id: 'alert-1',
  alertType: 'SepsisWarning',
  severity: 'Critical',
  details: 'SIRS criteria met',
  triggeredAt: '2026-06-19T12:00:00Z',
}

const qsofaScreenAlert = {
  id: 'alert-2',
  alertType: 'QsofaScreen',
  severity: 'Warning',
  details: 'qSOFA screen positive',
  triggeredAt: '2026-06-19T12:30:00Z',
}

describe('AlertReasoning', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
  })

  it('showsExplanationForLegacySepsisWarning', () => {
    const wrapper = mount(AlertReasoning, { props: { alert: sepsisAlert } })
    expect(wrapper.text()).toContain('SIRS / Sepsis Alert (Legacy)')
    expect(wrapper.text()).toContain('Historical alert')
    expect(wrapper.text()).toContain('SOFA delta')
  })

  it('showsExplanationForQsofaScreen', () => {
    const wrapper = mount(AlertReasoning, { props: { alert: qsofaScreenAlert } })
    expect(wrapper.text()).toContain('qSOFA Screen')
    expect(wrapper.text()).toContain('Bedside screen positive')
    expect(wrapper.text()).toContain('Recommend ordering SOFA labs (PaO₂')
  })

  it('showsRawDetailsForUnknownType', () => {
    const unknown = {
      id: 'alert-3',
      alertType: 'CustomUnknown',
      severity: 'Warning',
      details: 'Something unusual happened',
      triggeredAt: '2026-06-19T13:00:00Z',
    }
    const wrapper = mount(AlertReasoning, { props: { alert: unknown } })
    expect(wrapper.text()).toContain('CustomUnknown')
    expect(wrapper.text()).toContain('Something unusual happened')
  })
})