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

const BASE_URL = 'https://upskill-staging.measurequick.com';

async function captureScreenshots() {
  const browser = await chromium.launch({ headless: true });
  const context = await browser.newContext({
    viewport: { width: 1920, height: 1080 }
  });
  const page = await context.newPage();
  
  console.log('Capturing screenshots of deployed features...\n');
  
  try {
    // Login first
    console.log('Logging in...');
    await page.goto(`${BASE_URL}/training-login/`);
    await page.fill('#username', 'test_trainer');
    await page.fill('#password', 'password123');
    await page.click('button[type="submit"]');
    await page.waitForTimeout(3000);
    
    // Capture trainer dashboard
    console.log('Capturing trainer dashboard...');
    const dashboardUrl = page.url();
    console.log(`Current URL: ${dashboardUrl}`);
    await page.screenshot({ 
      path: 'screenshots/test-01-dashboard.png', 
      fullPage: true 
    });
    
    // Try to navigate to new pages
    const pages = [
      { name: 'venues-list', url: '/trainer/venue/list/' },
      { name: 'venue-manage', url: '/trainer/venue/manage/' },
      { name: 'profile-view', url: '/trainer/profile/' },
      { name: 'profile-edit', url: '/trainer/profile/edit/' },
      { name: 'organizers-list', url: '/trainer/organizer/list/' },
      { name: 'organizer-manage', url: '/trainer/organizer/manage/' }
    ];
    
    for (const pageInfo of pages) {
      console.log(`\nNavigating to ${pageInfo.name}...`);
      await page.goto(`${BASE_URL}${pageInfo.url}`);
      await page.waitForTimeout(2000);
      
      const currentUrl = page.url();
      const title = await page.title();
      console.log(`  URL: ${currentUrl}`);
      console.log(`  Title: ${title}`);
      
      await page.screenshot({ 
        path: `screenshots/test-${pageInfo.name}.png`, 
        fullPage: true 
      });
    }
    
    console.log('\nScreenshots captured successfully!');
    
  } catch (error) {
    console.error('Error:', error.message);
    await page.screenshot({ 
      path: 'screenshots/test-error.png', 
      fullPage: true 
    });
  } finally {
    await browser.close();
  }
}

captureScreenshots().catch(console.error);