import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { mount } from '@vue/test-utils'
import DischargeSummaryPanel from '@/components/patient/DischargeSummaryPanel.vue'

vi.mock('@/api/encounters', () => ({
  fetchDischargeSummaryStatus: vi.fn(() => Promise.resolve({
    status: 'Ready',
    dischargedAt: '2026-06-23T10:00:00Z',
  })),
  fetchDischargeSummaryContent: vi.fn(() => Promise.resolve('DISCHARGE SUMMARY\nPatient: Jane Doe')),
}))

describe('DischargeSummaryPanel', () => {
  beforeEach(() => {
    vi.useFakeTimers()
  })

  afterEach(() => {
    vi.useRealTimers()
  })

  it('rendersSummaryWhenDischarged', async () => {
    const wrapper = mount(DischargeSummaryPanel, {
      props: {
        encounterId: 'enc-1',
        discharged: true,
      },
    })

    await vi.waitFor(() => expect(wrapper.text()).toContain('DISCHARGE SUMMARY'))
    expect(wrapper.text()).toContain('Download')
  })

  it('hidesWhenNotDischarged', () => {
    const wrapper = mount(DischargeSummaryPanel, {
      props: {
        encounterId: 'enc-1',
        discharged: false,
      },
    })
    expect(wrapper.text()).toBe('')
  })
})
