/* eslint-disable */
// 测试脚本：只截一张图（借记卡权益列表）
const { chromium } = require('playwright')
const path = require('path')
const fs = require('fs')

const BASE = 'http://localhost:8080'
const OUT_DIR = path.resolve(__dirname, '../../prd/汇丰银行/screenshots')

;(async () => {
  console.log('启动 chromium...')
  const browser = await chromium.launch({ headless: true })
  const context = await browser.newContext({ viewport: { width: 1440, height: 900 }, deviceScaleFactor: 2 })
  const page = await context.newPage()

  console.log('访问登录页注入 token...')
  await page.goto(BASE + '/login', { waitUntil: 'domcontentloaded' })
  await page.evaluate(() => {
    localStorage.setItem('token', 'mock-token-' + Date.now())
    localStorage.setItem('username', 'admin')
  })

  const url = BASE + '/#/customization/hsbc/equity-products'
  console.log('访问', url)
  try {
    await page.goto(url, { waitUntil: 'networkidle', timeout: 15000 })
  } catch (e) {
    console.log('networkidle 超时，降级 domcontentloaded')
    await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 15000 })
  }
  await page.waitForTimeout(1500)

  if (!fs.existsSync(OUT_DIR)) fs.mkdirSync(OUT_DIR, { recursive: true })
  const file = path.join(OUT_DIR, '2-1-equity-products-list.png')
  await page.screenshot({ path: file, fullPage: true })
  const size = (fs.statSync(file).size / 1024).toFixed(0)
  console.log(`✓ ${file}  (${size}KB)`)

  await browser.close()
})()
