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

(async () => {
  const b = await chromium.launch();
  const p = await b.newPage();
  
  try {
    await p.goto("http://localhost:5265/login");
    console.log("✓ Login loaded");
    
    // Submit
    await p.fill("input[name=\"username\"]", "admin");
    await p.fill("input[name=\"password\"]", "admin");
    await p.click("button[type=\"submit\"]");
    
    // Wait for navigation
    try { await p.waitForNavigation({ timeout: 5000 }); } catch { }
    
    // Check cookie and URL
    const cookies = await p.context().cookies();
    const hasCookie = cookies.some(c => c.name === "quant_auth_token");
    const url = p.url();
    
    console.log(`Auth cookie: ${hasCookie ? "YES" : "NO"}`);
    console.log(`URL: ${url}`);
    
    if (url.includes("/dashboard") && !url.includes("/not-found")) {
      console.log("✓✓✓ SUCCESS!");
    }
    
    await p.screenshot({ path: "./auth-test.png" });
    
  } catch (e) {
    console.error(e.message);
  }
  
  await b.close();
})();
