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

test.describe('Frontend', () => {
  let page: Page

  test.beforeAll(async ({ browser }, testInfo) => {
    const context = await browser.newContext()
    page = await context.newPage()
  })

  test('can go on homepage (default locale redirect)', async ({ page }) => {
    // Root redirects to default locale /de
    await page.goto('/')

    // Title should contain "Payload CMS" (from localized SiteSettings or default)
    await expect(page).toHaveTitle(/Payload/)

    // Check page loaded successfully (status 200)
    const response = await page.goto('/')
    expect(response?.status()).toBeLessThan(400)
  })

  test('can access German locale page', async ({ page }) => {
    await page.goto('/de')

    // Should load without error
    const response = await page.goto('/de')
    expect(response?.status()).toBeLessThan(400)
  })

  test('can access English locale page', async ({ page }) => {
    await page.goto('/en')

    // Should load without error
    const response = await page.goto('/en')
    expect(response?.status()).toBeLessThan(400)
  })
})
