/** Maps stored `flag` keys to display labels (parity with CI `flags/*.php`). */
export const INCIDENT_LABELS: Record<string, string> = {
  payment: 'Payment',
  attendance: 'Attendance',
  grade: 'Grade',
  behavior: 'Behavior (General)',
  talking_off_task: 'Talking/off-task',
  calling_out: 'Calling out',
  minor_disruption: 'Minor disruption',
  minor_dress_code: 'Minor dress code',
  forgetting_materials: 'Forgetting materials',
  repeated_defiance: 'Repeated defiance',
  disrespectful_tone: 'Disrespectful tone',
  minor_profanity: 'Minor profanity',
  repeated_tardiness: 'Repeated tardiness',
  device_misuse: 'Device misuse',
  minor_conflict: 'Minor conflict/horseplay',
  bullying_harassment: 'Bullying/harassment',
  fighting_aggression: 'Fighting/aggression',
  threats: 'Threats',
  theft: 'Theft',
  vandalism: 'Vandalism',
  sexual_harassment: 'Sexual harassment',
  serious_cyber_incident: 'Serious cyber incident',
  contraband: 'Contraband',
  weapons_drugs: 'Weapons/drugs',
  other: 'Other',
}

export function incidentLabel(flagKey: string | null | undefined): string {
  const v = (flagKey ?? '').trim()
  if (!v) return 'N/A'
  return INCIDENT_LABELS[v] ?? v
}

export function normalizeIncidentKey(value: string): string {
  return value
    .trim()
    .toLowerCase()
    .replace(/[()]/g, '')
    .replace(/[^a-z0-9]+/g, '_')
    .replace(/^_+|_+$/g, '')
}
