/** * RiskRating represents the risk assessment details. * Aligned with backend Go struct. */ export interface RiskRating { /** Likelihood of the risk occurring (1-5). 0 = not rated. */ likelihood: number; /** Consequence/impact if the risk occurs (1-5). 0 = not rated. */ consequence: number; /** Calculated rating: likelihood × consequence (0-25). 0 = not rated. */ rating: number; /** Optional comment for context */ comment?: string; } export type RiskLevel = "unrated" | "low" | "medium" | "high" | "critical"; /** * Get risk level from rating (0-25). * - 0: Unrated * - 1-4: Low * - 5-9: Medium * - 10-16: High * - 17-25: Critical */ export function getRiskLevelFromRating(rating: number): RiskLevel { if (rating === 0) return "unrated"; if (rating <= 4) return "low"; if (rating <= 9) return "medium"; if (rating <= 16) return "high"; return "critical"; } /** * Check if a rating is considered "not rated" */ export function isRatingUnrated( rating: RiskRating | null | undefined, ): boolean { if (!rating) return true; return ( rating.rating === 0 || rating.likelihood === 0 || rating.consequence === 0 ); } export const riskLevelConfig: Record< RiskLevel, { label: string; bgColor: string; textColor: string; iconBgColor: string; iconTextColor: string; } > = { unrated: { label: "Nicht bewertet", bgColor: "bg-muted", textColor: "text-muted-foreground", iconBgColor: "bg-muted/50", iconTextColor: "text-muted-foreground", }, low: { label: "Niedrig", bgColor: "bg-success", textColor: "text-success", iconBgColor: "bg-success/10", iconTextColor: "text-success", }, medium: { label: "Mittel", bgColor: "bg-warning", textColor: "text-warning", iconBgColor: "bg-warning/10", iconTextColor: "text-warning", }, high: { label: "Hoch", bgColor: "bg-orange-500", textColor: "text-orange-500", iconBgColor: "bg-orange-500/10", iconTextColor: "text-orange-500", }, critical: { label: "Kritisch", bgColor: "bg-destructive", textColor: "text-destructive", iconBgColor: "bg-destructive/10", iconTextColor: "text-destructive", }, };