import { test } from '@playwright/test';

test('Open browser and wait for manual inspection', async ({ page }) => {
  console.log('\n🌐 Opening browser');
  console.log('📋 Watching console for errors...\n');

  const errors: string[] = [];
  const warnings: string[] = [];

  page.on('console', msg => {
    if (msg.type() === 'error') {
      const errorMsg = msg.text();
      errors.push(errorMsg);
      console.log(`❌ ERROR: ${errorMsg}`);
    } else if (msg.type() === 'warning') {
      warnings.push(msg.text());
    }
  });

  page.on('pageerror', error => {
    const errorMsg = `PAGE ERROR: ${error.message}`;
    errors.push(errorMsg);
    console.log(`\n💥 ${errorMsg}`);
    console.log(`Stack: ${error.stack}\n`);
  });

  await page.goto('/');

  console.log('\n✅ Page loaded');
  console.log('⏳ Waiting 10 seconds to capture any async errors...\n');

  await page.waitForTimeout(10000);

  console.log('\n📊 FINAL REPORT:');
  console.log(`   Errors: ${errors.length}`);
  console.log(`   Warnings: ${warnings.length}`);

  if (errors.length > 0) {
    console.log('\n🔴 ERRORS FOUND:');
    errors.forEach((err, i) => console.log(`   ${i + 1}. ${err}`));
  } else {
    console.log('\n✅ NO ERRORS FOUND!');
  }

  await page.screenshot({ path: 'tests/screenshots/final-browser-state.png', fullPage: true });
});
