import { Language } from '@/lib/compliance-i18n'

export interface Risk {
  id: string
  risk_id: string
  title: string
  description?: string
  category: string
  likelihood: number
  impact: number
  inherent_risk: string
  mitigating_controls?: string[] | null
  residual_likelihood?: number | null
  residual_impact?: number | null
  residual_risk?: string | null
  owner?: string
  status: string
  treatment_plan?: string
}

export interface Control {
  id: string
  control_id: string
  title: string
  domain: string
  status: string
}

export interface RiskHeatmapProps {
  risks: Risk[]
  controls?: Control[]
  lang?: Language
  onRiskClick?: (risk: Risk) => void
  onCellClick?: (likelihood: number, impact: number, risks: Risk[]) => void
  showComparison?: boolean
  height?: number
}

export const RISK_LEVEL_COLORS: Record<string, { bg: string; text: string; border: string }> = {
  low: { bg: 'bg-green-100', text: 'text-green-700', border: 'border-green-300' },
  medium: { bg: 'bg-yellow-100', text: 'text-yellow-700', border: 'border-yellow-300' },
  high: { bg: 'bg-orange-100', text: 'text-orange-700', border: 'border-orange-300' },
  critical: { bg: 'bg-red-100', text: 'text-red-700', border: 'border-red-300' },
}

export const RISK_BADGE_COLORS: Record<string, string> = {
  low: 'bg-green-500',
  medium: 'bg-yellow-500',
  high: 'bg-orange-500',
  critical: 'bg-red-500',
}

export const CATEGORY_OPTIONS: Record<string, { de: string; en: string }> = {
  data_breach: { de: 'Datenschutzverletzung', en: 'Data Breach' },
  compliance_gap: { de: 'Compliance-Luecke', en: 'Compliance Gap' },
  vendor_risk: { de: 'Lieferantenrisiko', en: 'Vendor Risk' },
  operational: { de: 'Betriebsrisiko', en: 'Operational Risk' },
  technical: { de: 'Technisches Risiko', en: 'Technical Risk' },
  legal: { de: 'Rechtliches Risiko', en: 'Legal Risk' },
}

export const STATUS_OPTIONS: Record<string, { de: string; en: string; color: string }> = {
  open: { de: 'Offen', en: 'Open', color: 'bg-slate-100 text-slate-700' },
  mitigated: { de: 'Gemindert', en: 'Mitigated', color: 'bg-green-100 text-green-700' },
  accepted: { de: 'Akzeptiert', en: 'Accepted', color: 'bg-blue-100 text-blue-700' },
  transferred: { de: 'Uebertragen', en: 'Transferred', color: 'bg-purple-100 text-purple-700' },
}

/**
 * Calculate risk level from likelihood and impact
 */
export const calculateRiskLevel = (likelihood: number, impact: number): string => {
  const score = likelihood * impact
  if (score >= 20) return 'critical'
  if (score >= 12) return 'high'
  if (score >= 6) return 'medium'
  return 'low'
}
