// Capture chaque page d'un portfolio dans le composeur (auto-contrôle dev).
// Usage : node scripts/dev-pages-shots.mjs <portfolioId>
import { chromium } from 'playwright'

const [, , id] = process.argv
const base = process.env.BASE_URL ?? 'http://localhost:3000'

const browser = await chromium.launch()
const page = await browser.newPage({ viewportSize: { width: 1600, height: 900 } })
await page.request.post(`${base}/api/auth/login`, {
  data: { password: process.env.NUXT_PORTFOLIO_PASSWORD ?? 'figureslibres' },
})
await page.goto(`${base}/portfolios/${id}`, { waitUntil: 'networkidle' })

const items = page.locator('aside .group')
const count = await items.count()
for (let i = 0; i < count; i++) {
  await items.nth(i).click()
  await page.waitForTimeout(1200)
  await page.screenshot({ path: `/app/data/cache/page-${i + 1}.png` })
  console.log(`page ${i + 1}/${count}`)
}
await browser.close()
