/**
 * Test the manage event page
 */

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

(async () => {
    const browser = await chromium.launch({ 
        headless: true,
        args: ['--no-sandbox', '--disable-setuid-sandbox']
    });
    
    const context = await browser.newContext({
        ignoreHTTPSErrors: true
    });
    
    const page = await context.newPage();
    
    console.log('🔍 TESTING MANAGE EVENT PAGE');
    console.log('=' .repeat(50));
    
    try {
        // Go directly to manage page
        console.log('📝 Navigating to /trainer/event/manage/...');
        const response = await page.goto('https://upskill-staging.measurequick.com/trainer/event/manage/', {
            waitUntil: 'networkidle',
            timeout: 30000
        });
        
        console.log('   Response status:', response.status());
        console.log('   Response URL:', response.url());
        
        const pageContent = await page.evaluate(() => {
            return {
                title: document.title,
                hasNavigation: document.querySelector('.hvac-trainer-menu') !== null,
                hasEventActions: document.querySelector('.hvac-event-actions') !== null,
                links: [],
                pageText: document.body?.innerText?.substring(0, 500) || ''
            };
            
        });
        
        console.log('   Page title:', pageContent.title);
        console.log('   Has HVAC Navigation:', pageContent.hasNavigation ? '✅' : '❌');
        console.log('   Has Event Actions:', pageContent.hasEventActions ? '✅' : '❌');
        
        console.log('\n📄 Page preview:');
        console.log(pageContent.pageText);
        
    } catch (error) {
        console.error('❌ Error:', error.message);
    } finally {
        await browser.close();
        console.log('\n✅ Test complete');
    }
})();