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('✓ Login form submitted');
    console.log('✓ Waiting 3 seconds for dashboard redirect...');
    
    await page.waitForNavigation({ waitUntil: 'load', timeout: 10000 });
    
    const url = page.url();
    const content = await page.content();
    
    console.log(`✓ Navigation complete`);
    console.log(`  URL: ${url}`);
    
    if (url.includes('/dashboard')) {
        if (content.includes('Not Found')) {
            console.log('✗ Dashboard URL but Not Found error');
        } else if (content.includes('관리자 대시보드')) {
            console.log('✓✓✓ SUCCESS: Dashboard fully loaded!');
        } else {
            console.log('✓ Dashboard page loaded (content check)');
        }
    } else {
        console.log('⚠ Not on dashboard URL');
    }
    
    await page.screenshot({ path: './login-final-screenshot.png' });
    
  } catch (e) {
    console.error('Test error:', e.message.substring(0, 70));
  }
  
  await browser.close();
})();
