const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext();
  const page = await context.newPage();

  page.on('console', msg => {
    console.log(`[BROWSER] ${msg.text()}`);
  });

  console.log('Logging in...');
  await page.goto('http://localhost:3000/.auth');
  await page.fill('input[type="text"]', 'admin');
  await page.fill('input[type="password"]', 'admin');
  await page.click('button:has-text("Login")');
  await page.waitForNavigation();

  console.log('Waiting 30s for indexing and plug activation...');
  await page.waitForTimeout(30000);

  // Check command palette
  console.log('Opening command palette to check for iCalendar commands...');
  await page.keyboard.press('Control+/');
  await page.waitForTimeout(2000);
  await page.keyboard.type('iCalendar:');
  await page.waitForTimeout(2000);

  const body = await page.innerText('body');
  console.log('--- Body Output ---');
  console.log(body);

  await page.screenshot({ path: 'repro_check.png', fullPage: true });
  await browser.close();
})();
