'use client'

export const RISK_BADGE: Record<string, string> = {
  CRITICAL: 'bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300',
  HIGH: 'bg-orange-100 text-orange-700 dark:bg-orange-900/40 dark:text-orange-300',
  MEDIUM: 'bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300',
  LOW: 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300',
}

export const RISK_LABEL: Record<string, string> = {
  CRITICAL: 'Kritisch', HIGH: 'Hoch', MEDIUM: 'Mittel', LOW: 'Niedrig',
}

export function RiskBadge({ level }: { level: string }) {
  return (
    <span className={`inline-block rounded px-2 py-0.5 text-sm font-semibold ${RISK_BADGE[level] || RISK_BADGE.LOW}`}>
      {RISK_LABEL[level] || level}
    </span>
  )
}

const TIER_BADGE: Record<string, string> = {
  P0: 'bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300',
  P1: 'bg-orange-100 text-orange-700 dark:bg-orange-900/40 dark:text-orange-300',
  P2: 'bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300',
  P3: 'bg-gray-100 text-gray-500 dark:bg-gray-700 dark:text-gray-300',
}

export function TierBadge({ tier, reason }: { tier?: string; reason?: string }) {
  if (!tier) return <span className="text-gray-300">—</span>
  return (
    <span title={reason} className={`inline-block rounded px-2 py-0.5 text-sm font-bold ${TIER_BADGE[tier] || TIER_BADGE.P3}`}>
      {tier}
    </span>
  )
}

const EVIDENCE_LABEL: Record<string, string> = {
  code: 'Code-nah', hybrid: 'Code + Prozess', process: 'Prozess', document: 'Dokumentation',
}

// "Code-nah" = der Scan kann es im Quellcode verorten → Code-Fix im Ticket möglich.
// Sonst = Prozess/Organisation: wir benennen den Sollzustand, kein Auto-Fix.
export function EvidenceTag({ et }: { et?: string }) {
  if (!et || !EVIDENCE_LABEL[et]) return null
  const codeish = et === 'code' || et === 'hybrid'
  return (
    <span
      title={codeish ? 'Code-Fix im Ticket möglich (wenn der Scan die Stelle sieht)' : 'Prozess-/Build-Maßnahme — kein Auto-Fix'}
      className={`inline-block rounded px-2 py-0.5 text-xs font-medium ${
        codeish
          ? 'bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-300'
          : 'bg-indigo-100 text-indigo-700 dark:bg-indigo-900/40 dark:text-indigo-300'}`}
    >
      {EVIDENCE_LABEL[et]}
    </span>
  )
}
