import { Loader2 } from "lucide-react";
import { useDashboard } from "./context/DashboardContext";
import { useTranslation } from "react-i18next";

export function TopCallIntents() {
  const { t } = useTranslation();
  const { stats, loading } = useDashboard();

  if (loading) {
    return (
      <div className="flex items-center justify-center h-64">
        <Loader2 className="w-8 h-8 text-slate-400 animate-spin" />
      </div>
    );
  }

  const intentData = stats?.topIntents || [];

  if (intentData.length === 0) {
    return (
      <div className="space-y-6">
        <div className="flex items-center justify-between">
          <h3 className="text-lg font-semibold text-white">{t('analytics.charts.topCallIntents')}</h3>
          <span className="text-sm text-slate-400">{t('analytics.charts.last24Hours')}</span>
        </div>
        <div className="text-center text-slate-400 py-8">
          {t('dashboard.noCallData')}
        </div>
      </div>
    );
  }

  return (
    <div className="space-y-6">
      <div className="flex items-center justify-between">
        <h3 className="text-lg font-semibold text-white">{t('analytics.charts.topCallIntents')}</h3>
        <span className="text-sm text-slate-400">{t('analytics.charts.last24Hours')}</span>
      </div>

      <div className="space-y-4">
        {intentData.map((intent) => (
          <div key={intent.name} className="space-y-2">
            <div className="flex items-center justify-between">
              <div className="flex items-center gap-3">
                <div className="w-3 h-3 bg-cyan-500 rounded-full"></div>
                <span className="text-white font-medium">{intent.name}</span>
              </div>

              <div className="flex items-center gap-4">
                <span className="text-2xl font-bold text-white">{intent.count}</span>
                <span className={`text-sm font-medium ${
                  intent.change.startsWith('+') ? 'text-green-500' : 'text-red-500'
                }`}>
                  {intent.change}
                </span>
              </div>
            </div>

            <div className="text-sm text-slate-400 text-right">
              {intent.percentage.toFixed(1)}%
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}
