import { chromium } from '@playwright/test';

(async () => {
  try {
    const browser = await chromium.launch();
    const page = await browser.newPage({ viewport: { width: 1280, height: 720 } });
    
    // Go to login page
    await page.goto('http://localhost:5265/login');
    console.log('Loaded login page');
    
    // Fill in credentials
    await page.fill('input[name="username"]', 'admin');
    await page.fill('input[name="password"]', 'admin');
    
    // Submit
    await page.click('button[type="submit"]');
    console.log('Submitted login form');
    
    // Wait for navigation
    await page.waitForNavigation({ waitUntil: 'networkidle' });
    console.log('Page navigated');
    
    // Check URL
    console.log('Current URL: ' + page.url());
    
    // Check content
    const content = await page.content();
    if (content.includes('Not Found')) {
        console.log('ERROR: Page shows Not Found');
    } else if (content.includes('관리자 대시보드') || content.includes('Dashboard')) {
        console.log('SUCCESS: Dashboard loaded');
    } else {
        console.log('Other content loaded');
    }
    
    // Take screenshot
    await page.screenshot({ path: './test-dashboard.png', fullPage: true });
    
    await browser.close();
  } catch (e) {
    console.error('Test failed:', e.message);
  }
})();
