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');
  
  // Check admin settings
  await page.goto('https://openweb.kangaroo-eel.ts.net/admin/settings');
  await page.waitForTimeout(3000);
  console.log('📍 Settings URL:', page.url());
  
  const settingsText = await page.evaluate(() => document.body.innerText);
  console.log('\n📝 Settings text (first 3000 chars):');
  console.log(settingsText.substring(0, 3000));
  
  // Check all admin sections
  const sections = ['general', 'interface', 'models', 'connections', 'evaluations', 'documents', 'webhooks', 'database'];
  
  for (const section of sections) {
    await page.goto(`https://openweb.kangaroo-eel.ts.net/admin/settings/${section}`);
    await page.waitForTimeout(2000);
    const text = await page.evaluate(() => document.body.innerText);
    if (text.toLowerCase().includes('memory')) {
      console.log(`\n🎯 Memory found in /admin/settings/${section}!`);
      console.log(text.substring(0, 2000));
    }
  }
  
  // Check user profile/settings
  await page.goto('https://openweb.kangaroo-eel.ts.net/profile');
  await page.waitForTimeout(3000);
  console.log('\n📍 Profile URL:', page.url());
  
  const profileText = await page.evaluate(() => document.body.innerText);
  console.log('\n📝 Profile text:');
  console.log(profileText.substring(0, 2000));
  
  await browser.close();
})();
