import { Chip, Tooltip } from '@mui/material'
import type { AIOutputError } from '../../domain/aiOutput'

const ERROR_CONFIG: Record<string, { label: string; color: string }> = {
  SCHEMA_VALIDATION: { label: 'Schema',     color: '#ea580c' },
  PROVIDER_TIMEOUT:  { label: 'Timeout',    color: '#c0392b' },
  INVALID_JSON:      { label: 'JSON',       color: '#c0392b' },
  EMPTY_RESPONSE:    { label: 'Leer',       color: '#d97706' },
  RATE_LIMIT:        { label: 'Rate Limit', color: '#7c3aed' },
}

export function AIErrorBadge({ error }: { error: AIOutputError }) {
  const { label, color } = ERROR_CONFIG[error.type] ?? { label: error.type, color: '#c0392b' }
  return (
    <Tooltip title={error.message} arrow>
      <Chip
        size="small"
        label={label}
        sx={{ bgcolor: `${color}18`, color, fontWeight: 700, fontSize: '0.65rem', cursor: 'default' }}
      />
    </Tooltip>
  )
}
