'use client'

import type { CoverageData } from '../types'

export function CoverageChart({ data }: { data: CoverageData[] }) {
  if (data.length === 0) {
    return (
      <div className="text-center py-8 text-slate-400">
        Keine Coverage-Daten verfuegbar
      </div>
    )
  }

  const sortedData = [...data].sort((a, b) => b.coverage_percent - a.coverage_percent)

  return (
    <div className="space-y-3">
      {sortedData.map((item) => (
        <div key={item.service}>
          <div className="flex items-center justify-between text-sm mb-1">
            <span className="text-slate-600 truncate max-w-[200px]">{item.display_name}</span>
            <span
              className={`font-medium ${
                item.coverage_percent >= 80 ? 'text-emerald-600' : item.coverage_percent >= 60 ? 'text-amber-600' : 'text-red-600'
              }`}
            >
              {item.coverage_percent.toFixed(1)}%
            </span>
          </div>
          <div className="h-2 bg-slate-100 rounded-full overflow-hidden">
            <div
              className={`h-full rounded-full transition-all ${
                item.coverage_percent >= 80 ? 'bg-emerald-500' : item.coverage_percent >= 60 ? 'bg-amber-500' : 'bg-red-500'
              }`}
              style={{ width: `${item.coverage_percent}%` }}
            />
          </div>
        </div>
      ))}
    </div>
  )
}
