import { chromium } from 'playwright';
import { pathToFileURL } from 'url';

const [, , htmlPath, pngPath] = process.argv;
if (!htmlPath || !pngPath) {
  console.error('Usage: node render-report-image.mjs <htmlPath> <pngPath>');
  process.exit(1);
}

const browser = await chromium.launch({ headless: true });
try {
  const page = await browser.newPage({ viewport: { width: 1240, height: 1754 } });
  await page.goto(pathToFileURL(htmlPath).href, { waitUntil: 'networkidle' });
  await page.screenshot({ path: pngPath, fullPage: true, type: 'png' });
} finally {
  await browser.close();
}
