/**
 * BoostMedia AI Content Generator Admin - Copyscape Status Badge
 *
 * @package BoostMedia_AI
 * @license GPL-2.0-or-later
 */

import {
  ShieldCheck,
  ShieldAlert,
  ShieldX,
  Shield,
} from 'lucide-react'
import { t } from '../../lib/i18n'

interface CopyscapeStatusBadgeProps {
  status?: string
  matchPercent?: number
  sectionsRewritten?: number
}

export function CopyscapeStatusBadge({ status, matchPercent, sectionsRewritten }: CopyscapeStatusBadgeProps) {
  if (!status || status === 'not_checked') {
    return null
  }

  const configs: Record<string, { label: string; icon: typeof ShieldCheck; className: string }> = {
    clean: {
      label: t('Plagiarism: Clean'),
      icon: ShieldCheck,
      className: 'text-green-700 bg-green-50 border-green-200',
    },
    improved: {
      label: t('Plagiarism: Rewritten'),
      icon: ShieldCheck,
      className: 'text-green-700 bg-green-50 border-green-200',
    },
    needs_review: {
      label: t('Plagiarism: Needs Review'),
      icon: ShieldAlert,
      className: 'text-amber-700 bg-amber-50 border-amber-200',
    },
    error: {
      label: t('Plagiarism: Error'),
      icon: ShieldX,
      className: 'text-red-700 bg-red-50 border-red-200',
    },
  }

  const config = configs[status] || {
    label: t('Plagiarism: Not Checked'),
    icon: Shield,
    className: 'text-bc-gray-500 bg-bc-gray-50 border-bc-gray-200',
  }

  const Icon = config.icon
  const titleParts: string[] = []
  if (matchPercent !== undefined && matchPercent > 0) {
    titleParts.push(matchPercent + '% ' + t('match'))
  }
  if (sectionsRewritten !== undefined && sectionsRewritten > 0) {
    titleParts.push(t('Sections rewritten') + ': ' + sectionsRewritten)
  }

  return (
    <span
      className={`inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-full border ${config.className}`}
      title={titleParts.join(' | ') || undefined}
    >
      <Icon className="w-3 h-3" />
      {config.label}
    </span>
  )
}
