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

(async () => {
  console.log("=== SIMPLE DIRECT TEST ===\n");
  
  const b = await chromium.launch({ headless: false });
  const p = await b.newPage();
  
  // 모든 콘솔 로그 출력
  p.on("console", msg => console.log(`  [${msg.type()}] ${msg.text()}`));
  
  try {
    console.log("1. Navigate to login...");
    // URL에 타임스탐프 추가 (캐시 무시)
    await p.goto("http://localhost:5265/login.html?v=" + Date.now());
    
    console.log("2. Submit form...");
    await p.fill("input[name='username']", "admin");
    await p.fill("input[name='password']", "admin");
    
    // Before submit - 현재 URL
    console.log("   URL before submit: " + p.url());
    
    await p.click("button[type='submit']");
    
    // 8초 동안 URL 변화 감시
    console.log("3. Monitoring for 8 seconds...");
    let lastUrl = "";
    for (let i = 0; i < 8; i++) {
      await new Promise(r => setTimeout(r, 1000));
      const currentUrl = p.url();
      if (currentUrl !== lastUrl) {
        console.log(`   [${i+1}s] ➜ ${currentUrl}`);
        lastUrl = currentUrl;
      }
    }
    
    console.log("\n4. RESULT: " + p.url());
    
  } catch (e) {
    console.error("Error:", e.message);
  }
  
  await b.close();
})();
