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

test.describe('Admin pages', () => {
  test.beforeEach(async ({ page }) => {
    // Log in as admin before each test
    await page.goto('/login')
    await page.getByLabel('E-Mail').fill('admin@dak-portal.de')
    await page.getByLabel('Passwort').fill('admin123')
    await page.getByRole('button', { name: 'Anmelden' }).click()
    await expect(page).toHaveURL(/\/dashboard/)
  })

  test('admin users page loads', async ({ page }) => {
    await page.goto('/admin/users')

    // Page heading should be visible
    await expect(page.getByRole('heading', { name: 'Benutzer' })).toBeVisible()

    // The create button should be present
    await expect(page.getByRole('button', { name: /neuen benutzer erstellen/i })).toBeVisible()

    // Table headers should be visible
    await expect(page.getByRole('columnheader', { name: 'Benutzername' })).toBeVisible()
    await expect(page.getByRole('columnheader', { name: 'E-Mail' })).toBeVisible()
    await expect(page.getByRole('columnheader', { name: 'Rolle' })).toBeVisible()
  })

  test('audit log page loads', async ({ page }) => {
    await page.goto('/admin/audit')

    // Page heading should be visible
    await expect(page.getByRole('heading', { name: 'Audit-Log' })).toBeVisible()

    // Filter section should be present
    await expect(page.getByText('Filter')).toBeVisible()
    await expect(page.getByLabel('Benutzer-ID')).toBeVisible()
    await expect(page.getByLabel('Aktion')).toBeVisible()
  })

  test('disclosures page loads', async ({ page }) => {
    await page.goto('/admin/disclosures')

    // Page heading should be visible
    await expect(page.getByRole('heading', { name: 'Freigabe-Anfragen' })).toBeVisible()
  })
})
