import { describe, it, expect } from 'vitest'
import { filterEncounters, matchesPatientSearch } from '@/composables/wardFilter'

const patients = [
  {
    encounterId: '1',
    firstName: 'Alice',
    lastName: 'Anderson',
    mrn: 'MRN-100',
    news2Score: 8,
    openAlertCount: 2,
    sepsisActive: true,
    sepsisBundleStatus: 'IN_PROGRESS',
  },
  {
    encounterId: '2',
    firstName: 'Bob',
    lastName: 'Baker',
    mrn: 'MRN-200',
    news2Score: 4,
    openAlertCount: 0,
    sepsisActive: false,
  },
  {
    encounterId: '3',
    firstName: 'Carol',
    lastName: 'Clark',
    mrn: 'MRN-300',
    news2Score: 7,
    openAlertCount: 1,
    sepsisActive: false,
    sepsisBundleStatus: 'IN_PROGRESS',
  },
]

describe('wardFilter', () => {
  it('matchesNameOrMrn', () => {
    expect(matchesPatientSearch(patients[0], 'alice')).toBe(true)
    expect(matchesPatientSearch(patients[0], 'MRN-100')).toBe(true)
    expect(matchesPatientSearch(patients[0], 'anderson')).toBe(true)
    expect(matchesPatientSearch(patients[0], 'xyz')).toBe(false)
  })

  it('filtersBySearch', () => {
    const result = filterEncounters(patients, { search: 'baker' })
    expect(result.map(p => p.encounterId)).toEqual(['2'])
  })

  it('filtersByHasAlerts', () => {
    const result = filterEncounters(patients, { hasAlerts: true })
    expect(result.map(p => p.encounterId)).toEqual(['1', '3'])
  })

  it('filtersBySepsisActive', () => {
    const result = filterEncounters(patients, { sepsisActive: true })
    expect(result.map(p => p.encounterId)).toEqual(['1', '3'])
  })

  it('filtersByCriticalNews2', () => {
    const result = filterEncounters(patients, { critical: true })
    expect(result.map(p => p.encounterId)).toEqual(['1', '3'])
  })

  it('combinesSearchAndFilters', () => {
    const result = filterEncounters(patients, {
      search: 'carol',
      hasAlerts: true,
      critical: true,
    })
    expect(result.map(p => p.encounterId)).toEqual(['3'])
  })
})
