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();
  
  console.log('🦀 Logging into OpenWebUI...');
  
  // 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);
  
  console.log('✅ Logged in, URL:', page.url());
  
  // Go to main page and explore
  await page.goto('https://openweb.kangaroo-eel.ts.net/');
  await page.waitForTimeout(3000);
  
  console.log('📍 Home URL:', page.url());
  
  // Get all links
  const links = await page.$$eval('a', links => 
    links.map(l => ({ text: l.textContent.trim(), href: l.href })).filter(l => l.text)
  );
  
  console.log('\n🔗 All links found:');
  links.forEach(l => console.log(`  ${l.text} -> ${l.href}`));
  
  // Look for memory-related text
  const bodyText = await page.evaluate(() => document.body.innerText);
  
  console.log('\n📝 Body text preview (first 2000 chars):');
  console.log(bodyText.substring(0, 2000));
  
  // Try admin panel
  await page.goto('https://openweb.kangaroo-eel.ts.net/admin');
  await page.waitForTimeout(3000);
  console.log('\n📍 Admin URL:', page.url());
  
  const adminText = await page.evaluate(() => document.body.innerText);
  console.log('\n📝 Admin text preview:');
  console.log(adminText.substring(0, 1500));
  
  // Try /memories
  await page.goto('https://openweb.kangaroo-eel.ts.net/memories');
  await page.waitForTimeout(3000);
  console.log('\n📍 Memories URL:', page.url());
  
  const memText = await page.evaluate(() => document.body.innerText);
  console.log('\n📝 Memories text preview:');
  console.log(memText.substring(0, 1500));
  
  await page.screenshot({ path: '/tmp/openweb_memories.png' });
  
  await browser.close();
})();
