// Phase 5 — Screenshots der befüllten Gitea-Instanz (1920x1080) nach docs/screenshots/.
// Nutzt das bereits installierte Puppeteer aus Sites(staging) (kein eigener Download).
import { createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath } from "node:url";

const staging = "C:/Program Files (x86)/TempoBill/Zeiterfassung.Cloud/Sites(staging)";
const require = createRequire(path.join(staging, "package.json"));
const puppeteer = require("puppeteer-core");
// Kein Chrome auf der Maschine — Edge ist Chromium und tut es genauso.
const CHROME = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";

const here = path.dirname(fileURLToPath(import.meta.url));
const outDir = path.join(here, "..", "docs", "screenshots");

const SHOTS = [
  ["skills-core-repos", "https://zeiterfassung.cloud/skillfactor/skills-core"],
  ["marketplace-readme", "https://zeiterfassung.cloud/skillfactor/skills-core/marketplace"],
  ["sanitize-pr", "https://zeiterfassung.cloud/skillfactor/skills-community/recruitment-consultant/pulls/1"],
  ["recruiter-repo", "https://zeiterfassung.cloud/skillfactor/skills-core/recruitment-consultant"],
];

const browser = await puppeteer.launch({
  executablePath: CHROME,
  headless: true,
  args: ["--no-sandbox", "--ignore-certificate-errors"],
  defaultViewport: { width: 1920, height: 1080 },
});
const page = await browser.newPage();
for (const [name, url] of SHOTS) {
  await page.goto(url, { waitUntil: "networkidle2", timeout: 60000 });
  await new Promise((r) => setTimeout(r, 1200));
  const file = path.join(outDir, `${name}.png`);
  await page.screenshot({ path: file });
  console.log(`shot: ${file}`);
}
await browser.close();
console.log("done");
