'use client'

import type { BQASMetrics } from '../types'
import { IntentScoresChart } from './IntentScoresChart'
import { FailedTestsList } from './FailedTestsList'

export function SyntheticTab({
  syntheticMetrics,
  isRunningSynthetic,
  runSyntheticTests,
}: {
  syntheticMetrics: BQASMetrics | null
  isRunningSynthetic: boolean
  runSyntheticTests: () => void
}) {
  return (
    <div className="space-y-6">
      <div className="bg-white rounded-xl border border-slate-200 p-6">
        <div className="flex items-center justify-between mb-6">
          <div>
            <h3 className="text-lg font-semibold text-slate-900">Synthetic Test Suite</h3>
            <p className="text-sm text-slate-500">LLM-generierte Variationen fuer Robustheit-Tests</p>
          </div>
          <button
            onClick={runSyntheticTests}
            disabled={isRunningSynthetic}
            className={`px-4 py-2 rounded-lg text-sm font-medium transition-all ${
              isRunningSynthetic
                ? 'bg-teal-100 text-teal-600 cursor-wait'
                : 'bg-teal-600 text-white hover:bg-teal-700 active:scale-95'
            }`}
          >
            {isRunningSynthetic ? 'Laeuft...' : 'Tests starten'}
          </button>
        </div>

        {syntheticMetrics ? (
          <>
            <div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
              <div className="text-center p-4 bg-slate-50 rounded-lg">
                <p className="text-2xl font-bold text-slate-900">{syntheticMetrics.total_tests}</p>
                <p className="text-xs text-slate-500">Generierte Tests</p>
              </div>
              <div className="text-center p-4 bg-emerald-50 rounded-lg">
                <p className="text-2xl font-bold text-emerald-600">{syntheticMetrics.passed_tests}</p>
                <p className="text-xs text-slate-500">Bestanden</p>
              </div>
              <div className="text-center p-4 bg-blue-50 rounded-lg">
                <p className="text-2xl font-bold text-blue-600">{syntheticMetrics.avg_composite_score.toFixed(2)}</p>
                <p className="text-xs text-slate-500">Avg Score</p>
              </div>
              <div className="text-center p-4 bg-purple-50 rounded-lg">
                <p className="text-2xl font-bold text-purple-600">{syntheticMetrics.avg_coherence.toFixed(2)}</p>
                <p className="text-xs text-slate-500">Coherence</p>
              </div>
            </div>

            <div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
              <div>
                <h4 className="font-medium text-slate-900 mb-4">Intent-Variationen</h4>
                <IntentScoresChart scores={syntheticMetrics.scores_by_intent} />
              </div>
              <div>
                <h4 className="font-medium text-slate-900 mb-4">Fehlgeschlagene Tests</h4>
                <FailedTestsList testIds={syntheticMetrics.failed_test_ids} />
              </div>
            </div>
          </>
        ) : (
          <div className="text-center py-12 text-slate-400">
            <svg className="w-16 h-16 mx-auto mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z" />
            </svg>
            <p>Noch keine synthetischen Tests ausgefuehrt</p>
            <p className="text-sm mt-2">Klicke &quot;Tests starten&quot; um Variationen zu generieren</p>
          </div>
        )}
      </div>
    </div>
  )
}
