/**
 * Screenshots de validación visual — Etapa 1 Sprint 1.5.
 *
 * Captura 3 vistas que muestran la identidad InQ aplicada:
 *  1. workspace.png   — CTAs naranjas, Simular button, tabs
 *  2. report-tabs.png — tab activo naranja en el reporte
 *  3. switch-on.png   — switch de automatización en estado ON naranja
 *
 * Estos screenshots son evidencia de que el cambio de --primary a naranja
 * se ve correctamente en la aplicación real.
 */
import { test } from '@playwright/test'
import { resolve } from 'path'
import { mkdirSync } from 'fs'
import { fileURLToPath } from 'url'

const __dirname = fileURLToPath(new URL('.', import.meta.url))
const BPMN_DIR = resolve(__dirname, '../../public/sample-processes')
const OUT_DIR = resolve(__dirname, '../screenshots/etapa-1')

test.beforeAll(() => { mkdirSync(OUT_DIR, { recursive: true }) })

test('screenshot workspace — CTAs naranjas visibles', async ({ page }) => {
  await page.goto('/')
  await page.locator('#bpmn-file-input').setInputFiles(resolve(BPMN_DIR, 'simple-linear.bpmn'))
  await page.waitForURL(/\/workspace\//, { timeout: 15_000 })
  await page.waitForSelector('button:has-text("Simular")', { timeout: 10_000 })
  await page.waitForTimeout(1_000)

  await page.screenshot({ path: resolve(OUT_DIR, 'workspace.png'), fullPage: false })
})

test('screenshot switch ON — switch de automatización naranja', async ({ page }) => {
  await page.goto('/')
  await page.locator('#bpmn-file-input').setInputFiles(resolve(BPMN_DIR, 'simple-linear.bpmn'))
  await page.waitForURL(/\/workspace\//, { timeout: 15_000 })
  await page.waitForSelector('button:has-text("Simular")', { timeout: 10_000 })
  await page.waitForTimeout(1_500)

  // Hacer click en el primer task del BPMN para abrir el ActivityPanel
  await page.locator('[data-element-id="task1"]').first().click()
  await page.waitForTimeout(500)

  // Encender el switch de automatización
  const toggle = page.getByRole('switch', { name: /automatizable/i })
  await toggle.click()
  await page.waitForTimeout(300)

  await page.screenshot({ path: resolve(OUT_DIR, 'switch-on.png'), fullPage: false })
})

test('screenshot report-tabs — tab activo naranja', async ({ page }) => {
  await page.goto('/')
  await page.locator('#bpmn-file-input').setInputFiles(resolve(BPMN_DIR, 'medium-with-gateways.bpmn'))
  await page.waitForURL(/\/workspace\//, { timeout: 15_000 })
  await page.waitForSelector('button:has-text("Simular")', { timeout: 10_000 })
  await page.waitForTimeout(1_500)

  const simBtn = page.getByRole('button', { name: 'Simular' })
  await simBtn.click()
  await page.waitForURL(/\/report\//, { timeout: 20_000 })
  await page.waitForSelector('button:has-text("Exportar PDF")', { timeout: 20_000 })

  await page.screenshot({ path: resolve(OUT_DIR, 'report-tabs.png'), fullPage: false })
})
