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

const encounter = {
  roomBed: 'ICU-3C',
  department: 'Icu',
  attendingPhysician: 'Dr. Smith',
  admissionReason: 'Sepsis workup',
  patient: {
    mrn: 'MRN-000123',
    firstName: 'Jane',
    lastName: 'Doe',
    dateOfBirth: '1985-03-20',
    gender: 'F',
    bloodType: 'AbNegative',
    allergies: 'Penicillin, Latex',
    emergencyContactName: 'John Doe',
    emergencyContactPhone: '555-0100',
  },
}

describe('PatientBanner', () => {
  it('showsDemographicsAndEncounterFields', () => {
    const wrapper = mount(PatientBanner, { props: { encounter } })
    expect(wrapper.text()).toContain('Jane Doe')
    expect(wrapper.text()).toContain('MRN-000123')
    expect(wrapper.text()).toContain('AB-')
    expect(wrapper.text()).toContain('ICU')
    expect(wrapper.text()).toContain('ICU-3C')
    expect(wrapper.text()).toContain('Dr. Smith')
    expect(wrapper.text()).toContain('Sepsis workup')
    expect(wrapper.text()).toContain('John Doe')
  })

  it('highlightsKnownAllergies', () => {
    const wrapper = mount(PatientBanner, { props: { encounter } })
    expect(wrapper.text()).toContain('Penicillin, Latex')
    const strip = wrapper.find('[role="status"]')
    expect(strip.classes().join(' ')).toMatch(/bg-red-600/)
  })

  it('showsNkdaWhenNoAllergies', () => {
    const wrapper = mount(PatientBanner, {
      props: {
        encounter: {
          ...encounter,
          patient: { ...encounter.patient, allergies: null },
        },
      },
    })
    expect(wrapper.text()).toContain('NKDA')
    const strip = wrapper.find('[role="status"]')
    expect(strip.classes().join(' ')).not.toMatch(/bg-red-600/)
  })
})
