/** QA-1: Genetik (FEAT-5/GEN-1) — Probeverpaarung inkl. SCHECKE-Warnung. */
import { de, expect, gotoSection, test } from './fixtures'

const t = de.pages.genetik

function genotypeInput(page: import('@playwright/test').Page, parent: string) {
  return page
    .locator('fieldset.parent-selector')
    .filter({ has: page.getByText(parent, { exact: true }) })
    .getByLabel(t.genotypeLabel)
}

test('Probeverpaarung rechnet client-seitig und zeigt Nachkommen-Farbschläge', async ({ page }) => {
  await gotoSection(page, de.nav.genetics)
  await expect(page.getByText(t.subtitle)).toBeVisible()
  await expect(page.getByText(t.needBoth)).toBeVisible()

  await genotypeInput(page, t.father).fill('AA CC DD EE GG PP spsp rere')
  await genotypeInput(page, t.mother).fill('aa CC DD EE GG PP spsp rere')

  await expect(page.getByRole('heading', { name: t.resultsTitle })).toBeVisible()
  // AA × aa -> alle Nachkommen Aa = Agouti (Farbschlag-Karte)
  await expect(page.locator('.farbschlag-card').filter({ hasText: 'Agouti' }).first()).toBeVisible()
})

test('Schecke × Schecke zeigt die deutsche Letalwarnung', async ({ page }) => {
  await gotoSection(page, de.nav.genetics)
  // Beide Eltern Spsp (Schecke): SpSp ist letal -> Warnhinweis
  await genotypeInput(page, t.father).fill('Aa CC DD EE GG PP Spsp rere')
  await genotypeInput(page, t.mother).fill('Aa CC DD EE GG PP Spsp rere')

  await expect(page.getByRole('heading', { name: t.warningsTitle })).toBeVisible()
  await expect(page.getByText(de.genetics.warnings.SCHECKE_LETHAL)).toBeVisible()
})

test('ungültiger Genotyp zeigt die deutsche Fehlermeldung', async ({ page }) => {
  await gotoSection(page, de.nav.genetics)
  await genotypeInput(page, t.father).fill('kein genotyp')
  await expect(page.getByText(t.genotypeInvalid)).toBeVisible()
})
