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

test.beforeEach(async ({ page }) => {
  await page.addInitScript(() => {
    window.localStorage.setItem('dlbdi:staffToken', 'dev-admin-token')
  })
})

test('admin system status page renders without a blank screen', async ({ page }) => {
  await page.goto('/admin/system')
  await expect(page.getByRole('heading', { name: '系统健康' })).toBeVisible()
  await expect(page.getByText('database', { exact: true })).toBeVisible()
  await expect(page.getByText('objectStorage', { exact: true })).toBeVisible()
  await expect(page.getByText(/本地上传模式|S3/)).toBeVisible()
})

test('admin exception center renders filters and empty/loading states', async ({ page }) => {
  await page.goto('/admin/exceptions')
  await expect(page.getByRole('heading', { name: '异常处理中心' })).toBeVisible()
  await expect(page.getByPlaceholder('搜索异常类型、对象、编号或错误信息')).toBeVisible()
})

test('admin data service page renders request workspace', async ({ page }) => {
  await page.goto('/admin/data-service/requests')
  await expect(page.getByRole('heading', { name: '数据服务需求' })).toBeVisible()
  await expect(page.getByPlaceholder('搜索编号、单位、联系人、主题')).toBeVisible()
})

test('admin data page maintenance renders cases table', async ({ page }) => {
  test.setTimeout(60_000)
  await page.goto('/admin/data-service/page', { waitUntil: 'domcontentloaded' })
  await expect(page.getByRole('heading', { name: '数据页面维护' })).toBeVisible()
  await expect(page.getByRole('button', { name: '保存' })).toBeVisible()
})

test('admin org tree renders organization panels', async ({ page }) => {
  await page.goto('/admin/org')
  await expect(page.getByRole('heading', { name: '组织架构' })).toBeVisible()
  await expect(page.getByText('新增部门')).toBeVisible()
  await expect(page.getByText('岗位', { exact: true })).toBeVisible()
})

test('admin staff roles render role families', async ({ page }) => {
  await page.goto('/admin/staff-roles')
  await expect(page.getByRole('heading', { name: '角色与权限' })).toBeVisible()
  await expect(page.getByText('运营中心', { exact: true })).toBeVisible()
})
