import { defineConfig, devices } from "@playwright/test";

// Docker Chrome Playwright configuration.
// Connects to a remote browserless/chrome container via CDP.
//
// Usage:
//   1. Start the Chrome container:
//      docker compose -f docker-compose.chrome.yml up -d
//
//   2. Run tests:
//      npx playwright test --config=playwright.docker.config.ts

const CDP_URL = process.env.PLAYWRIGHT_CDP_URL || "http://localhost:3000";

export default defineConfig({
  testDir: "./test/e2e",
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 1 : undefined,
  reporter: "list",

  use: {
    baseURL: process.env.PLAYWRIGHT_BASE_URL || "http://localhost:8056",
    trace: "on-first-retry",
    headless: process.env.PLAYWRIGHT_HEADLESS !== "false",
  },

  // Connect to remote Chrome via CDP instead of launching locally.
  // browserless/chrome exposes CDP at port 3000.
  projects: [
    {
      name: "docker-chrome",
      use: {
        ...devices["Desktop Chrome"],
        launchOptions: {
          // Not used for remote connection, but placeholder for clarity
        },
      },
    },
  ],
});