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('🦀 Scuttling to OpenWebUI...');
  
  // Go to login page
  await page.goto('https://openweb.kangaroo-eel.ts.net/auth');
  await page.waitForTimeout(2000);
  
  // Fill in credentials
  await page.fill('input[type="email"], input[name="email"], #email', 'anthonymau@gmail.com');
  await page.fill('input[type="password"], input[name="password"], #password', 'RecOvery2026!');
  
  console.log('🔑 Credentials filled');
  
  // Click sign in
  await page.click('button[type="submit"], button:has-text("Sign in")');
  
  // Wait for navigation
  await page.waitForTimeout(5000);
  
  console.log('📍 Current URL:', page.url());
  
  // Look for memory/settings page
  await page.goto('https://openweb.kangaroo-eel.ts.net/settings');
  await page.waitForTimeout(3000);
  
  console.log('📍 Settings URL:', page.url());
  
  // Take screenshot
  await page.screenshot({ path: '/tmp/openweb_settings.png' });
  
  // Get page content
  const content = await page.content();
  const text = await page.evaluate(() => document.body.innerText);
  
  console.log('\n📝 Page text preview:');
  console.log(text.substring(0, 3000));
  
  // Try to find memory section
  const memoryLinks = await page.$$eval('a', links => 
    links.filter(l => l.textContent.toLowerCase().includes('memory')).map(l => l.href)
  );
  
  console.log('\n🔗 Memory links found:', memoryLinks);
  
  await browser.close();
})();
