import { test, expect } from '@playwright/test';
import { LoginPage } from './LoginPage';
import { TEST_USERS } from '../data/test-users';

test.describe('Debug Dashboard URL', () => {
    test('Check dashboard URL after successful login', async ({ page }) => {
        const loginPage = new LoginPage(page);
        const trainer = TEST_USERS.trainer;
        
        // Navigate to login page and login
        await loginPage.navigateToLogin();
        await loginPage.login(trainer.username, trainer.password);
        
        // Wait for navigation and check URL
        await page.waitForTimeout(5000);
        
        console.log(`Current URL after login: ${page.url()}`);
        console.log(`Page title: ${await page.title()}`);
        
        // Check if we're on a dashboard page
        const possibleDashboardUrls = [
            '/hvac-dashboard/',
            '/community-dashboard/',
            '/dashboard/',
            '/trainer/dashboard/',
            '/wp-admin/',
            '/events/community/list/',
            '/community-events/',
            '/my-events/'
        ];
        
        for (const url of possibleDashboardUrls) {
            await page.goto(url).catch(() => {});
            await page.waitForTimeout(2000);
            
            const currentUrl = page.url();
            console.log(`Tested URL: ${url} => ${currentUrl}`);
            
            // Check if there are dashboard elements
            const hasCreateEvent = await page.locator('a:has-text("Create Event")').isVisible().catch(() => false);
            const hasEventsList = await page.locator('table').isVisible().catch(() => false);
            const hasStats = await page.locator('.hvac-stats-grid, .stats-section, .dashboard-stats').isVisible().catch(() => false);
            
            if (hasCreateEvent || hasEventsList || hasStats) {
                console.log(`  Found dashboard elements at: ${currentUrl}`);
                console.log(`    Create Event button: ${hasCreateEvent}`);
                console.log(`    Events list: ${hasEventsList}`);
                console.log(`    Stats section: ${hasStats}`);
            }
        }
    });
});