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

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  
  try {
    await page.goto('http://localhost:5265/login');
    await page.fill('input[name="username"]', 'admin');
    await page.fill('input[name="password"]', 'admin');
    await page.click('button[type="submit"]');
    
    console.log('Waiting for dashboard via auth-redirect...');
    
    try {
      await page.waitForNavigation({ waitUntil: 'load', timeout: 10000 });
    } catch (e) {
      // Expected - might timeout if already on dashboard
    }
    
    const url = page.url();
    const content = await page.content();
    
    console.log('Final URL: ' + url);
    
    if (url.includes('/dashboard')) {
        if (content.includes('관리자 대시보드')) {
            console.log('✓✓✓ SUCCESS: Login complete and dashboard loaded!');
        } else if (content.includes('Not Found')) {
            console.log('✗ Not Found error');
        }
    } else {
        console.log('URL is: ' + url);
    }
    
    await page.screenshot({ path: './test-result.png' });
    
  } catch (e) {
    console.error('Error:', e.message);
  }
  
  await browser.close();
})();
