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

(async () => {
  const b = await chromium.launch();
  const p = await b.newPage();
  
  console.log("=== FULL LOGIN TEST (SIMPLE) ===\n");
  
  try {
    // Login
    await p.goto("http://localhost:5265/login");
    await p.fill("input[name=\"username\"]", "admin");
    await p.fill("input[name=\"password\"]", "admin");
    console.log("✓ Clicking login button...");
    await p.click("button[type=\"submit\"]");
    
    // Wait for redirect (3 seconds + network)
    console.log("✓ Waiting 4 seconds for Blazor + redirect...");
    await new Promise(r => setTimeout(r, 4000));
    
    // Check final state
    const url = p.url();
    const content = await p.content();
    
    console.log(`\nResult:`);
    console.log(`  URL: ${url}`);
    
    if (url.includes("/dashboard")) {
      if (content.includes("관리자 대시보드")) {
        console.log("  ✓✓✓ SUCCESS: Dashboard loaded!");
      } else if (content.includes("Not Found")) {
        console.log("  ✗ Not Found error");
      } else {
        console.log("  ✓ Dashboard page (content may vary)");
      }
    } else if (url.includes("/not-found")) {
      console.log("  ✗ Redirected to /not-found");
    } else if (url.includes("/login")) {
      console.log("  ⚠ Still at login page");
    } else {
      console.log("  ? Other URL");
    }
    
    // Take screenshot
    await p.screenshot({ path: "./final-login-result.png", fullPage: true });
    
  } catch (e) {
    console.error("Error:", e.message);
  }
  
  await b.close();
})();
