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

(async () => {
  const browser = await chromium.launch({ headless: true });
  const context = await browser.newContext({
    userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36'
  });
  const page = await context.newPage();
  
  // Login
  await page.goto('https://openweb.kangaroo-eel.ts.net/auth');
  await page.waitForTimeout(2000);
  await page.fill('input[type="email"]', 'anthonymau@gmail.com');
  await page.fill('input[type="password"]', 'RecOvery2026!');
  await page.click('button[type="submit"]');
  await page.waitForTimeout(5000);
  
  // Go to main page and click user menu
  await page.goto('https://openweb.kangaroo-eel.ts.net/');
  await page.waitForTimeout(3000);
  
  // Click on user menu
  await page.click('button[aria-label="User menu"], button:has-text("User menu"), [data-testid="user-menu"]');
  await page.waitForTimeout(2000);
  
  // Get all menu items
  const menuItems = await page.$$eval('[role="menuitem"], .dropdown-menu a, [class*="menu"] a', 
    items => items.map(i => ({ text: i.textContent.trim(), href: i.href || 'no-href' }))
  );
  
  console.log('📝 User menu items:');
  menuItems.forEach(item => console.log(`  - ${item.text} (${item.href})`));
  
  // Look for Settings in menu
  const settingsItem = menuItems.find(i => i.text.toLowerCase().includes('setting'));
  if (settingsItem) {
    console.log('\n🎯 Found settings, clicking...');
    await page.click(`text=${settingsItem.text}`);
    await page.waitForTimeout(3000);
    
    console.log('📍 URL:', page.url());
    const text = await page.evaluate(() => document.body.innerText);
    console.log('📝 Content preview:', text.substring(0, 2500));
  }
  
  // Also try /workspace
  await page.goto('https://openweb.kangaroo-eel.ts.net/workspace');
  await page.waitForTimeout(3000);
  console.log('\n📍 Workspace URL:', page.url());
  const wsText = await page.evaluate(() => document.body.innerText);
  console.log('📝 Workspace content:', wsText.substring(0, 2000));
  
  await browser.close();
})();
