import { chromium } from 'playwright';

const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: { width: 1400, height: 900 } });
const page = await context.newPage();

import { mkdirSync } from 'fs';
mkdirSync('C:/tmp/playwright_screenshots', { recursive: true });

// Navigate to login
await page.goto('http://localhost:3000/login');
await page.waitForLoadState('networkidle');
await page.screenshot({ path: 'C:/tmp/playwright_screenshots/login_page.png', fullPage: true });

// Debug HTML form
const formHTML = await page.locator('form').innerHTML().catch(() => 'no form found');
console.log('Form HTML:', formHTML.substring(0, 1000));

const allInputs = await page.locator('input').all();
console.log('Inputs count:', allInputs.length);
for (const input of allInputs) {
  const name = await input.getAttribute('name');
  const type = await input.getAttribute('type');
  const placeholder = await input.getAttribute('placeholder');
  console.log(`Input: name=${name}, type=${type}, placeholder=${placeholder}`);
}

const allButtons = await page.locator('button').all();
for (const btn of allButtons) {
  const text = await btn.textContent();
  const type = await btn.getAttribute('type');
  console.log(`Button: text="${text?.trim()}", type=${type}`);
}

await browser.close();
