<script lang="ts">
  import { Badge } from '$lib/components/ui/badge'

  type StatusKind = 'risk' | 'severity' | 'execution' | 'type' | 'default'

  let {
    value,
    kind = 'default',
    class: className
  }: {
    value: string
    kind?: StatusKind
    class?: string
  } = $props()

  const variantMap: Record<
    StatusKind,
    Record<string, 'default' | 'secondary' | 'destructive' | 'outline'>
  > = {
    risk: {
      destructive: 'destructive',
      config_mutation: 'secondary'
    },
    severity: {
      critical: 'destructive',
      warning: 'secondary',
      info: 'default'
    },
    execution: {
      failed: 'destructive',
      denied: 'destructive',
      revoked: 'destructive',
      cancelled: 'destructive',
      completed: 'default',
      running: 'secondary',
      approved: 'secondary'
    },
    type: {
      runbook: 'secondary',
      investigation: 'default'
    },
    default: {}
  }

  function variant(): 'default' | 'secondary' | 'destructive' | 'outline' {
    return variantMap[kind]?.[value] ?? (kind === 'default' ? 'default' : 'outline')
  }
</script>

<Badge variant={variant()} class={className}>{value}</Badge>
