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

async function testDashboardNavigation() {
    console.log('🔍 TESTING DASHBOARD NAVIGATION SYSTEM');
    console.log('================================================================================');
    
    const browser = await chromium.launch({ headless: false });
    const context = await browser.newContext();
    const page = await context.newPage();
    
    try {
        // Login as regular trainer
        console.log('📝 Logging in as regular trainer...');
        await page.goto('https://upskill-staging.measurequick.com/wp-login.php');
        await page.fill('#user_login', 'test_trainer');
        await page.fill('#user_pass', 'TestTrainer123!');
        await page.click('#wp-submit');
        await page.waitForURL('**/trainer/dashboard/**', { timeout: 15000 });
        console.log('✅ Regular trainer login successful');
        
        // Analyze dashboard navigation
        console.log('🔍 Analyzing dashboard navigation...');
        const dashboardNavResult = await page.evaluate(() => {
            return {
                url: window.location.href,
                hasMenuSystem: document.querySelector('.hvac-trainer-menu-wrapper') !== null,
                hasTrainerMenu: document.querySelector('.hvac-trainer-menu') !== null,
                hasSimpleNav: document.querySelector('.hvac-trainer-nav') !== null,
                navMenuItems: document.querySelectorAll('.hvac-trainer-menu li').length,
                navLinks: Array.from(document.querySelectorAll('.hvac-trainer-menu a, .hvac-nav-link')).map(a => ({
                    text: a.textContent.trim(),
                    href: a.href,
                    classes: a.className
                })),
                hasDropdowns: document.querySelectorAll('.sub-menu, .dropdown-arrow').length > 0,
                menuHTML: document.querySelector('nav')?.outerHTML?.slice(0, 500) || 'none',
                allNavElements: Array.from(document.querySelectorAll('nav, .menu, .navigation')).map(el => ({
                    tagName: el.tagName,
                    classes: el.className,
                    id: el.id
                }))
            };
        });
        
        console.log('📊 Dashboard navigation analysis:', dashboardNavResult);
        
        await page.screenshot({ path: 'dashboard-navigation-analysis.png', fullPage: true });
        
        console.log('================================================================================');
        console.log('🎯 DASHBOARD NAVIGATION ANALYSIS COMPLETE');
        
    } catch (error) {
        console.error('❌ Error during dashboard navigation analysis:', error);
        await page.screenshot({ path: 'dashboard-nav-analysis-error.png', fullPage: true });
    } finally {
        await browser.close();
    }
}

testDashboardNavigation();