// Capture d'écran de contrôle (dev) : node scripts/dev-screenshot.mjs <path> <out.png>
import { chromium } from 'playwright'

const [, , path = '/', out = '/app/data/cache/screenshot.png'] = process.argv
const base = process.env.BASE_URL ?? 'http://localhost:3000'

const browser = await chromium.launch()
const page = await browser.newPage({ viewportSize: { width: 1440, height: 900 } })

// Session : login via l'API puis navigation
await page.request.post(`${base}/api/auth/login`, {
  data: { password: process.env.NUXT_PORTFOLIO_PASSWORD ?? 'figureslibres' },
})
await page.goto(`${base}${path}`, { waitUntil: 'networkidle' })
await page.waitForTimeout(1000)
await page.screenshot({ path: out, fullPage: false })
await browser.close()
console.log(`screenshot: ${out}`)
