import { test, expect } from '@playwright/test';

test.use({ storageState: 'tests/e2e/.auth/waitlist-user.json' });

test('onboarding page loads for authenticated user', async ({ page }) => {
  console.log('Navigating to onboarding with auth...');

  await page.goto('http://localhost:9000/en/dashboard/onboarding');
  await page.waitForLoadState('networkidle');
  await page.waitForTimeout(3000);

  const url = page.url();
  console.log('Final URL:', url);

  // Take screenshot
  await page.screenshot({ path: 'tests/e2e/screenshots/onboarding-quick.png', fullPage: true });

  // Check page content
  const title = await page.title();
  console.log('Page title:', title);

  // Get any visible text
  const bodyText = await page.locator('body').innerText();
  console.log('Body text (first 500 chars):', bodyText.substring(0, 500));

  // Check for specific elements
  const hasProgressBar = await page.locator('[class*="progress"]').isVisible().catch(() => false);
  console.log('Has progress bar:', hasProgressBar);

  const hasWelcome = await page.locator('text=/Welcome|مرحباً/').isVisible().catch(() => false);
  console.log('Has welcome text:', hasWelcome);

  const hasError = await page.locator('[class*="error"], .text-red').isVisible().catch(() => false);
  console.log('Has error:', hasError);
});
