import { describe, it, expect, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import CriticalAlertBanner from '@/components/alerts/CriticalAlertBanner.vue'
import { useAlertStore } from '@/stores/alerts'

const { mockPush } = vi.hoisted(() => ({
  mockPush: vi.fn(),
}))

vi.mock('vue-router', () => ({
  useRouter: () => ({ push: mockPush }),
}))

describe('CriticalAlertBanner', () => {
  it('rendersCriticalAlertsAndDismisses', async () => {
    setActivePinia(createPinia())
    const alertStore = useAlertStore()
    alertStore.bannerAlerts = [{
      id: 'alert-1',
      alertType: 'SOFA_SEPSIS',
      severity: 'CRITICAL',
      status: 'OPEN',
      details: 'SOFA delta >= 2',
      explanation: {
        narrativeSummary: 'SOFA 6 — respiratory (+2), renal (+2).',
      },
    }]

    const wrapper = mount(CriticalAlertBanner)
    expect(wrapper.text()).toContain('Sepsis Alert (SOFA)')
    expect(wrapper.text()).toContain('SOFA 6 — respiratory (+2), renal (+2).')

    const dismissButton = wrapper.findAll('button').find(button => button.text() === 'Dismiss')
    await dismissButton.trigger('click')
    expect(alertStore.bannerAlerts).toEqual([])
  })
})
