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

test('dump page content', async ({ page }) => {
  const baseURL = process.env.BASE_URL || 'http://localhost:3003';
  await page.goto(`${baseURL}/auth`);
  console.log('--- AUTH PAGE URL ---', page.url());
  console.log('--- AUTH PAGE TITLE ---', await page.title());
  
  // Try to sign in
  const emailInput = page.locator('input[type="email"]').or(page.locator('input[name="email"]')).first();
  if (await emailInput.isVisible({ timeout: 5000 })) {
     await emailInput.fill('e2etest');
     await page.locator('input[type="password"]').first().fill('Test12345!');
     await page.getByRole('button', { name: /sign in/i }).or(page.locator('button[type="submit"]')).first().click();
     await page.waitForURL(/.*app.*/, { timeout: 10000 });
  } else {
     console.log('Email input not visible');
     // Maybe already logged in or different page
     await page.goto(`${baseURL}/app`);
  }
  
  console.log('--- APP PAGE URL ---', page.url());
  await page.waitForTimeout(2000);
  const bodyText = await page.innerText('body');
  console.log('--- BODY TEXT START ---');
  console.log(bodyText.substring(0, 1000));
  console.log('--- BODY TEXT END ---');
  
  const links = await page.getByRole('link').allInnerTexts();
  console.log('--- LINKS ---', links);
});
