import { describe, it, expect } from 'vitest'
import { render, screen } from '@testing-library/react'

import { RemediationPlan } from '../RemediationPlan'

describe('RemediationPlan', () => {
  it('leitet Maßnahmen nur aus echten offenen Punkten ab', () => {
    const results = {
      results: [
        { doc_type: 'impressum', error: '', completeness_pct: 50, checks: [
          { id: 'a', label: 'Registernummer', passed: false, severity: 'HIGH', matched_text: '', level: 1, hint: 'HRB ergänzen' },
          { id: 'b', label: 'Telefon', passed: false, severity: 'MEDIUM', matched_text: '', level: 1 },
          { id: 'c', label: 'OK-Feld', passed: true, severity: 'HIGH', matched_text: 'x', level: 1 },
          { id: 'd', label: 'Info-Hinweis', passed: false, severity: 'INFO', matched_text: '', level: 1 },
        ] },
      ],
    }
    render(<RemediationPlan results={results} />)
    // 2 Maßnahmen (HIGH + MEDIUM); OK + INFO ausgeschlossen
    expect(screen.getByText(/Abstellmaßnahmen & Tickets \(2\)/)).toBeInTheDocument()
    expect(screen.getByText(/Registernummer/)).toBeInTheDocument()
    expect(screen.getByText('HRB ergänzen')).toBeInTheDocument()   // hint = Maßnahme
    expect(screen.queryByText(/Info-Hinweis/)).not.toBeInTheDocument()
    expect(screen.queryByText(/OK-Feld/)).not.toBeInTheDocument()
  })

  it('zeigt Erfolg, wenn keine offenen Punkte', () => {
    const results = {
      results: [
        { doc_type: 'impressum', error: '', completeness_pct: 100, checks: [
          { id: 'a', label: 'X', passed: true, severity: 'HIGH', matched_text: 'x', level: 1 },
        ] },
      ],
    }
    render(<RemediationPlan results={results} />)
    expect(screen.getByText(/kein Handlungsbedarf/)).toBeInTheDocument()
  })
})
