/**
 * Vendor Compliance — Transfers Tab E2E Test
 *
 * Prueft: Drittlandtransfer-Tab, Erklaerungen, Adequacy-Liste
 */

import { test, expect } from '@playwright/test'

const BASE = process.env.PLAYWRIGHT_BASE_URL || 'https://macmini:3007'

test.describe('Vendor Compliance — Transfers', () => {
  test('Transfers tab is accessible', async ({ page }) => {
    await page.goto(`${BASE}/sdk/vendor-compliance/transfers`)
    await page.waitForLoadState('networkidle')

    // Page should show transfer heading
    const body = await page.textContent('body')
    expect(body).toContain('Drittlandtransfers')

    await page.screenshot({ path: 'e2e/test-results/transfers-tab.png', fullPage: true })
  })

  test('Explanation section is visible', async ({ page }) => {
    await page.goto(`${BASE}/sdk/vendor-compliance/transfers`)
    await page.waitForLoadState('networkidle')

    // Check for the three explanation cards
    const body = await page.textContent('body')
    expect(body).toContain('Was muss ich tun')
    expect(body).toContain('Angemessenheitsbeschluss')
    expect(body).toContain('DPF-Zertifizierung')
    expect(body).toContain('SCC + TIA')

    await page.screenshot({ path: 'e2e/test-results/transfers-explanations.png' })
  })

  test('Adequacy countries list is expandable', async ({ page }) => {
    await page.goto(`${BASE}/sdk/vendor-compliance/transfers`)
    await page.waitForLoadState('networkidle')

    // Click on the details summary to expand
    const summary = page.locator('summary', { hasText: 'Angemessenheitsbeschluss' })
    if (await summary.isVisible()) {
      await summary.click()
      await page.waitForTimeout(300)

      // Check for country names
      const body = await page.textContent('body')
      expect(body).toContain('Schweiz')
      expect(body).toContain('Japan')
      expect(body).toContain('Vereinigte Staaten')

      await page.screenshot({ path: 'e2e/test-results/transfers-adequacy-list.png', fullPage: true })
    }
  })

  test('Schrems II info box is present', async ({ page }) => {
    await page.goto(`${BASE}/sdk/vendor-compliance/transfers`)
    await page.waitForLoadState('networkidle')

    const body = await page.textContent('body')
    expect(body).toContain('Schrems II')

    await page.screenshot({ path: 'e2e/test-results/transfers-schrems.png' })
  })
})
