const { chromium } = require('playwright');

async function testLogin() {
  const browser = await chromium.launch({ headless: false });
  const page = await browser.newPage();
  
  try {
    // Try port 3000 first
    console.log('Testing port 3000...');
    await page.goto('http://localhost:3000/login-new', { timeout: 10000 });
    await page.screenshot({ path: 'login-page.png', fullPage: true });
    console.log('✓ Screenshot saved as login-page.png');
  } catch (error1) {
    try {
      // Try port 3001
      console.log('Port 3000 failed, trying 3001...');
      await page.goto('http://localhost:3001/login-new', { timeout: 10000 });
      await page.screenshot({ path: 'login-page.png', fullPage: true });
      console.log('✓ Screenshot saved as login-page.png');
    } catch (error2) {
      try {
        // Try port 4321 (default Astro)
        console.log('Port 3001 failed, trying 4321...');
        await page.goto('http://localhost:4321/login-new', { timeout: 10000 });
        await page.screenshot({ path: 'login-page.png', fullPage: true });
        console.log('✓ Screenshot saved as login-page.png');
      } catch (error3) {
        console.log('All ports failed. Starting dev server...');
        console.log('Error 3000:', error1.message);
        console.log('Error 3001:', error2.message);
        console.log('Error 4321:', error3.message);
      }
    }
  }
  
  await browser.close();
}

testLogin().catch(console.error);