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

test('should login via wp-admin and access dashboard', async ({ page }) => {
    // Login via wp-admin
    await page.goto('https://upskill-staging.measurequick.com/wp-admin');
    await page.fill('#user_login', 'test_trainer');
    await page.fill('#user_pass', 'password123!');
    await page.click('#wp-submit');
    
    // Wait for login to complete
    await page.waitForLoadState('networkidle');
    
    // Check if we're logged in (should not be on login page)
    const currentUrl = page.url();
    console.log('Current URL after login:', currentUrl);
    expect(currentUrl).not.toContain('wp-login.php');
    
    // Now navigate to HVAC dashboard
    await page.goto('https://upskill-staging.measurequick.com/hvac-dashboard');
    await page.waitForLoadState('networkidle');
    
    // Check for dashboard elements
    const pageContent = await page.content();
    console.log('Dashboard page contains "dashboard":', pageContent.toLowerCase().includes('dashboard'));
    
    // Check for stat cards
    const statCards = await page.locator('.hvac-stat-card').count();
    console.log('Number of stat cards found:', statCards);
    
    // Take screenshot for debugging
    await page.screenshot({ path: 'wp-admin-login-test.png', fullPage: true });
});