'use client';

import { JiraAnomaly } from '@/services/integrations/jira/anomaly-detection';
import { AnomalyItem } from './AnomalyItem';

interface AnomalyListProps {
  anomalies: JiraAnomaly[];
  loading: boolean;
  error: string | null;
}

export function AnomalyList({ anomalies, loading, error }: AnomalyListProps) {
  if (error) {
    return (
      <div className="bg-red-50 border border-red-200 rounded-lg p-3 mb-4">
        <p className="text-red-700 text-sm">❌ {error}</p>
      </div>
    );
  }

  if (loading) {
    return (
      <div className="flex items-center justify-center py-8">
        <div className="text-center">
          <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-2"></div>
          <p className="text-sm text-gray-600">Analyse en cours...</p>
        </div>
      </div>
    );
  }

  if (anomalies.length === 0) {
    return (
      <div className="text-center py-8">
        <div className="text-4xl mb-2">✅</div>
        <p className="text-[var(--foreground)] font-medium">
          Aucune anomalie détectée
        </p>
        <p className="text-sm text-[var(--muted-foreground)]">
          Toutes les métriques sont dans les seuils normaux
        </p>
      </div>
    );
  }

  return (
    <div className="grid grid-cols-1 lg:grid-cols-2 gap-3">
      {anomalies.map((anomaly) => (
        <AnomalyItem key={anomaly.id} anomaly={anomaly} />
      ))}
    </div>
  );
}
