import { describe, it, expect, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import SepsisBoardView from '@/views/SepsisBoardView.vue'

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

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

vi.mock('@/composables/usePolling', () => ({
  usePolling: () => {},
}))

const bundles = [
  {
    id: 'b1',
    encounterId: 'enc-1',
    firstName: 'Alice',
    lastName: 'A',
    mrn: 'M1',
    department: 'Icu',
    roomBed: '101',
    recognizedAt: '2026-06-23T12:00:00Z',
    deadlineAt: '2026-06-23T15:00:00Z',
    complianceStatus: 'IN_PROGRESS',
    elements: [
      { id: 'e1', elementType: 'BloodCultures', status: 'Completed' },
      { id: 'e2', elementType: 'SerumLactate', status: 'Pending' },
    ],
  },
]

vi.mock('@/api/sepsis', () => ({
  fetchSepsisBundles: vi.fn(() => Promise.resolve({ items: bundles, totalCount: 1 })),
}))

describe('SepsisBoardView', () => {
  it('rendersBundleBoardWithSummary', async () => {
    setActivePinia(createPinia())
    const wrapper = mount(SepsisBoardView)
    await vi.waitFor(() => expect(wrapper.text()).toContain('Alice A'))
    expect(wrapper.text()).toContain('Sepsis Bundle Board')
    expect(wrapper.text()).toContain('Serum lactate')
  })
})
