const ALERT_TYPE_LABELS = {
  SEPSIS_WARNING: 'Sepsis Warning (SIRS — Legacy)',
  QSOFA_WARNING: 'qSOFA Alert (Legacy)',
  QSOFA_SCREEN: 'qSOFA Screen',
  SOFA_SEPSIS: 'Sepsis Alert (SOFA)',
  SOFA_WARNING: 'SOFA Warning',
  GCS_CRITICAL: 'GCS Critical (≤ 8)',
  GCS_WARNING: 'GCS Warning (9–12)',
  NEWS2_WARNING: 'NEWS2 Warning',
  NEWS2_EMERGENCY: 'NEWS2 Emergency',
  RAPID_DETERIORATION: 'Rapid Deterioration',
  CRITICAL_HEART_RATE: 'Critical Heart Rate',
  CRITICAL_TEMP_C: 'Critical Temperature',
  CRITICAL_POTASSIUM_MEQ_L: 'Critical Potassium',
  CRITICAL_SPO2: 'Critical SpO₂',
  CRITICAL_RESP_RATE: 'Critical Respiratory Rate',
  CRITICAL_WBC_K_UL: 'Critical WBC',
  CRITICAL_SYSTOLIC_BP: 'Critical Systolic BP',
  CRITICAL_DIASTOLIC_BP: 'Critical Diastolic BP',
  CRITICAL_LACTATE_MMOL_L: 'Critical Lactate',
  CRITICAL_AVPU: 'Critical AVPU',
  CRITICAL_GLUCOSE_MG_DL: 'Critical Glucose',
  WARNING_HEART_RATE: 'Warning Heart Rate',
  WARNING_TEMP_C: 'Warning Temperature',
  WARNING_POTASSIUM_MEQ_L: 'Warning Potassium',
  WARNING_SPO2: 'Warning SpO₂',
  WARNING_RESP_RATE: 'Warning Respiratory Rate',
  WARNING_WBC_K_UL: 'Warning WBC',
  WARNING_SYSTOLIC_BP: 'Warning Systolic BP',
  WARNING_DIASTOLIC_BP: 'Warning Diastolic BP',
  WARNING_LACTATE_MMOL_L: 'Warning Lactate',
  WARNING_GLUCOSE_MG_DL: 'Warning Glucose',
  CRITICAL_PAO2_MMHG: 'Critical PaO₂',
  WARNING_PAO2_MMHG: 'Warning PaO₂',
  CRITICAL_PLATELET_K_UL: 'Critical Platelets',
  WARNING_PLATELET_K_UL: 'Warning Platelets',
  CRITICAL_BILIRUBIN_MG_DL: 'Critical Bilirubin',
  WARNING_BILIRUBIN_MG_DL: 'Warning Bilirubin',
  CRITICAL_CREATININE_MG_DL: 'Critical Creatinine',
  WARNING_CREATININE_MG_DL: 'Warning Creatinine',
}

const BUNDLE_TRIGGER_LABELS = {
  SOFA_SEPSIS: 'SOFA delta ≥ 2',
  SEPSIS_WARNING: 'SIRS criteria (Legacy)',
  QSOFA_WARNING: 'qSOFA alert (Legacy)',
}

export function alertTypeLabel(type) {
  if (!type) return ''
  return ALERT_TYPE_LABELS[type]
    ?? type.replace(/_/g, ' ')
}

export function bundleTriggerLabel(triggerType) {
  if (!triggerType) return ''
  return BUNDLE_TRIGGER_LABELS[triggerType] ?? triggerType.replace(/_/g, ' ')
}

export function alertStatusToApiFilter(status) {
  return status ?? null
}

const OBSERVATION_LABELS = {
  HEART_RATE: 'Heart Rate',
  RESP_RATE: 'Respiratory Rate',
  SPO2: 'SpO₂',
  SYSTOLIC_BP: 'Systolic BP',
  TEMP_C: 'Temperature',
  AVPU: 'AVPU',
  SUPPLEMENTAL_O2: 'Supplemental O₂',
  WBC_K_UL: 'WBC',
  GCS_EYE: 'GCS Eye',
  GCS_VERBAL: 'GCS Verbal',
  GCS_MOTOR: 'GCS Motor',
}

export function observationCodeLabel(code) {
  return OBSERVATION_LABELS[code] ?? code?.replace(/_/g, ' ') ?? ''
}

const BUNDLE_ELEMENT_LABELS = {
  BloodCultures: 'Blood cultures',
  SerumLactate: 'Serum lactate',
  BroadSpectrumAntibiotics: 'Broad-spectrum antibiotics',
  IvFluidResuscitation: 'IV fluid resuscitation',
}

export function bundleElementLabel(elementType) {
  return BUNDLE_ELEMENT_LABELS[elementType] ?? elementType
}