/** * Shared severity ladder for calls and incidents: routine < minor < moderate < major. * Every call/incident gets one of these four. `"unknown"` (and any other * unrecognized value) is a legacy value still present on historical docs — * treat it as "no severity", not as a fifth level. */ import type { ReactElement } from "react"; import { SeverityMark } from "@/components/marks/SeverityMark"; export type Severity = "routine" | "minor" | "moderate" | "major"; export const SEVERITY_ORDER: Record = { routine: 0, minor: 1, moderate: 2, major: 3 }; export const SEVERITY_LABEL: Record = { routine: "Routine", minor: "Minor", moderate: "Moderate", major: "Major" }; /** * Validated against the dataviz all-pairs colour-blindness checker (see * UI_REDESIGN.md §2.3). Severity is the ONLY hue channel in the whole app — * moderate/major carry colour, routine/minor are neutral ink with no hue. * Colour is never the sole channel: SeverityMark also carries glyph shape * and spine thickness so the ladder survives grayscale. */ export const SEVERITY_COLORS: Record = { routine: "var(--ink-muted)", minor: "var(--ink-2)", moderate: "var(--sev-moderate)", major: "var(--sev-major)", }; export function isKnownSeverity(s: string | null | undefined): s is Severity { return s === "routine" || s === "minor" || s === "moderate" || s === "major"; } /** Legacy/unset severities rank below `routine` so a recency-sorted list never confuses them with a real (low) severity. */ export function severityRank(s: string | null | undefined): number { return isKnownSeverity(s) ? SEVERITY_ORDER[s] : -1; } /** Renders the full severity mark (glyph + word chip). Use `` directly for more control (spine, size, label-off). */ export function severityBadge(severity: string | null | undefined): ReactElement | null { if (!isKnownSeverity(severity)) return null; return ; }