// Visual sampler: screenshot each palette + a later mood for review.
import { chromium } from 'playwright';
import { spawn } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import path from 'node:path';

const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const PORT = 8742;
const server = spawn('python3', ['-m', 'http.server', String(PORT), '--bind', '127.0.0.1'], {
  cwd: path.join(root, 'dist'),
  stdio: 'ignore',
});
await new Promise((r) => setTimeout(r, 800));

const browser = await chromium.launch({
  args: ['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader'],
});
const page = await browser.newPage({ viewport: { width: 1280, height: 720 } });
await page.goto(`http://127.0.0.1:${PORT}/`, { waitUntil: 'load' });
await page.waitForTimeout(5000);
await page.screenshot({ path: path.join(root, 'check', 'p0-mercury.png') });
await page.keyboard.press('c');
await page.waitForTimeout(5000);
await page.screenshot({ path: path.join(root, 'check', 'p1-rose.png') });
await page.keyboard.press('c');
await page.waitForTimeout(5000);
await page.screenshot({ path: path.join(root, 'check', 'p2-emerald.png') });
await browser.close();
server.kill();
console.log('done');
