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

test.describe('Debug Date Format', () => {
    test('Check date input format', async ({ page }) => {
        const loginPage = new LoginPage(page);
        const dashboardPage = new DashboardPage(page);
        const trainer = TEST_USERS.trainer;
        
        // Login and navigate to create event
        await loginPage.navigateToLogin();
        await loginPage.login(trainer.username, trainer.password);
        await dashboardPage.clickCreateEvent();
        
        // Wait for form to load
        await page.waitForTimeout(3000);
        
        // Check current values in date fields
        const startDateInput = page.locator('#EventStartDate');
        const startDateValue = await startDateInput.inputValue();
        console.log(`Current start date value: "${startDateValue}"`);
        
        // Try different date formats
        const dateFormats = [
            '2025-06-01',  // ISO format
            '06/01/2025',  // US format
            '6/1/2025',    // US format without leading zeros
            '01/06/2025',  // EU format
            'June 1, 2025' // Long format
        ];
        
        for (const dateFormat of dateFormats) {
            try {
                await startDateInput.clear();
                await startDateInput.fill(dateFormat);
                await page.keyboard.press('Tab'); // Trigger any formatting
                
                const newValue = await startDateInput.inputValue();
                console.log(`Input: "${dateFormat}" -> Result: "${newValue}"`);
            } catch (e) {
                console.log(`Error with format "${dateFormat}": ${e.message}`);
            }
        }
        
        // Take screenshot
        await page.screenshot({ path: 'date-format-debug.png', fullPage: true });
        console.log('\nScreenshot saved as date-format-debug.png');
    });
});