const ALERT_TYPE_LABELS = {
  SepsisWarning: 'Sepsis Warning (SIRS — Legacy)',
  QsofaWarning: 'qSOFA Alert (Legacy)',
  QsofaScreen: 'qSOFA Screen',
  SofaSepsis: 'Sepsis Alert (SOFA)',
  SofaWarning: 'SOFA Warning',
  GcsCritical: 'GCS Critical (≤ 8)',
  GcsWarning: 'GCS Warning (9–12)',
  News2Warning: 'NEWS2 Warning',
  News2Emergency: 'NEWS2 Emergency',
  RapidDeterioration: 'Rapid Deterioration',
  CriticalHeartRate: 'Critical Heart Rate',
  CriticalTempC: 'Critical Temperature',
  CriticalPotassiumMeqL: 'Critical Potassium',
  CriticalSpo2: 'Critical SpO₂',
  CriticalRespRate: 'Critical Respiratory Rate',
  CriticalWbcKUl: 'Critical WBC',
  CriticalSystolicBp: 'Critical Systolic BP',
  CriticalDiastolicBp: 'Critical Diastolic BP',
  CriticalLactateMmolL: 'Critical Lactate',
  CriticalAvpu: 'Critical AVPU',
  CriticalGlucoseMgDl: 'Critical Glucose',
  WarningHeartRate: 'Warning Heart Rate',
  WarningTempC: 'Warning Temperature',
  WarningPotassiumMeqL: 'Warning Potassium',
  WarningSpo2: 'Warning SpO₂',
  WarningRespRate: 'Warning Respiratory Rate',
  WarningWbcKUl: 'Warning WBC',
  WarningSystolicBp: 'Warning Systolic BP',
  WarningDiastolicBp: 'Warning Diastolic BP',
  WarningLactateMmolL: 'Warning Lactate',
  WarningGlucoseMgDl: 'Warning Glucose',
  CriticalPao2MmHg: 'Critical PaO₂',
  WarningPao2MmHg: 'Warning PaO₂',
  CriticalPlateletKUl: 'Critical Platelets',
  WarningPlateletKUl: 'Warning Platelets',
  CriticalBilirubinMgDl: 'Critical Bilirubin',
  WarningBilirubinMgDl: 'Warning Bilirubin',
  CriticalCreatinineMgDl: 'Critical Creatinine',
  WarningCreatinineMgDl: '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(/([A-Z])/g, '_$1').slice(1).toUpperCase()
}

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

export function alertStatusToApiFilter(status) {
  const map = {
    Open: 'OPEN',
    Acknowledged: 'ACKNOWLEDGED',
    Resolved: 'RESOLVED',
    Escalated: 'ESCALATED',
  }
  return map[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
}