import { defineConfig, devices } from "@playwright/test";
import * as dotenv from "dotenv";
import * as path from "path";

dotenv.config({ path: path.resolve(__dirname, ".env") });

export default defineConfig({
  testDir: "./tests",
  fullyParallel: false,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 1 : 0,
  workers: 1,
  reporter: "list",

  // LLMs son lentos — timeouts generosos
  timeout: 60_000,
  expect: { timeout: 30_000 },

  use: {
    baseURL: process.env.ELEMENT_URL || "http://localhost:8080",
    headless: true,
    screenshot: "on",
    trace: "retain-on-failure",
    video: "retain-on-failure",
    actionTimeout: 30_000,
    // NO usamos storageState — usamos persistent context para preservar IndexedDB
  },

  outputDir: "./test-results",

  globalSetup: "./global-setup.ts",

  projects: [
    {
      name: "chromium",
      use: { ...devices["Desktop Chrome"] },
    },
  ],
});
