const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({ headless: 'new', args: ['--no-sandbox', '--disable-setuid-sandbox'] });
  const page = await browser.newPage();
  await page.setViewport({ width: 1920, height: 1080 });

  const BASE = 'http://localhost:5173';
  const outDir = '/Users/nathan/Work/DataPointer/prop-data-guard/screenshots';

  // 1. Login page
  console.log('Capturing login...');
  await page.goto(`${BASE}/login`, { waitUntil: 'networkidle2' });
  await new Promise(r => setTimeout(r, 1000));
  await page.screenshot({ path: `${outDir}/01_login.png`, fullPage: false });

  // Login
  await page.type('input[placeholder="用户名"]', 'admin');
  await page.type('input[type="password"]', 'admin123');
  await page.click('.login-btn');
  await page.waitForNavigation({ waitUntil: 'networkidle2' });
  await new Promise(r => setTimeout(r, 2000));

  // Helper to capture a page
  async function capture(path, filename, waitMs = 3000) {
    console.log(`Capturing ${path}...`);
    await page.goto(`${BASE}${path}`, { waitUntil: 'networkidle2' });
    await new Promise(r => setTimeout(r, waitMs));
    await page.screenshot({ path: `${outDir}/${filename}`, fullPage: false });
  }

  await capture('/dashboard', '02_dashboard.png');
  await capture('/datasource', '03_datasource.png');
  await capture('/metadata', '04_metadata.png');
  await capture('/category', '05_category.png');
  await capture('/project', '06_project.png');
  await capture('/task', '07_task.png');
  await capture('/classification', '08_classification.png');
  await capture('/report', '09_report.png');
  await capture('/system', '10_system.png');

  await browser.close();
  console.log('All screenshots captured!');
})();
