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

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

async function checkPageStatus() {
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage();
  
  console.log('Checking page status on staging server...\n');
  
  const pages = [
    { name: 'Registration Form', url: '/trainer-registration/' },
    { name: 'Venues List', url: '/trainer/venue/list/' },
    { name: 'Manage Venue', 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: 'Manage Organizer', url: '/trainer/organizer/manage/' }
  ];
  
  for (const pageInfo of pages) {
    try {
      const response = await page.goto(`${BASE_URL}${pageInfo.url}`, {
        waitUntil: 'domcontentloaded',
        timeout: 10000
      });
      
      const status = response.status();
      const title = await page.title();
      
      console.log(`${pageInfo.name}:`);
      console.log(`  URL: ${pageInfo.url}`);
      console.log(`  Status: ${status}`);
      console.log(`  Title: ${title}`);
      
      if (status === 200) {
        await page.screenshot({ 
          path: `screenshots/${pageInfo.name.toLowerCase().replace(/\s+/g, '-')}.png`,
          fullPage: true
        });
        console.log(`  Screenshot: Saved`);
      }
      
      console.log('');
      
    } catch (error) {
      console.log(`${pageInfo.name}: ERROR - ${error.message}\n`);
    }
  }
  
  await browser.close();
}

checkPageStatus().catch(console.error);