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

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage({ viewport: { width: 1280, height: 720 } });
  
  try {
    await page.goto('http://localhost:5265/login');
    console.log('✓ Login page loaded');
    
    // Check if Blazor component rendered
    const content1 = await page.content();
    if (content1.includes('관리자 아이디')) {
        console.log('✓ Blazor login form rendered');
    }
    
    // Fill credentials
    await page.fill('input', 'admin');
    const inputs = await page.$$('input[type="password"]');
    if (inputs.length > 0) {
        await inputs[0].fill('admin');
    }
    
    await page.click('button[type="submit"]');
    console.log('✓ Login submitted');
    
    // Wait for navigation
    await page.waitForNavigation({ waitUntil: 'networkidle', timeout: 5000 });
    
    console.log('✓ Navigation complete');
    console.log('  URL: ' + page.url());
    
    // Take screenshot
    await page.screenshot({ path: './login-success.png', fullPage: true });
    console.log('✓ Screenshot saved');
    
  } catch (e) {
    console.error('Error:', e.message);
  }
  
  await browser.close();
})();
