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

test.describe('External user public flow smoke', () => {
  test('login page renders expected fields', async ({ page }) => {
    await page.goto('/auth/login', { waitUntil: 'domcontentloaded' });
    await expect(page.getByRole('heading', { name: 'Sign In' })).toBeVisible();
    await expect(page.getByPlaceholder('Enter your email')).toBeVisible();
    await expect(page.getByPlaceholder('Enter your password')).toBeVisible();
    await expect(page.getByRole('button', { name: 'Sign In' })).toBeVisible();
  });

  test('choose-role page renders and routes to company onboarding', async ({ page }) => {
    await page.goto('/users/choose-role', { waitUntil: 'domcontentloaded' });
    await expect(page.getByRole('heading', { name: 'What would you like to do today?' })).toBeVisible();
    await page.waitForTimeout(1200);

    await page.getByRole('button', { name: /Company/i }).first().click();
    await expect(page).toHaveURL(/\/onboarding\?roleKey=COMPANY&schemaId=company_onboarding_v1&intent=company/, { timeout: 15000 });
  });

  test('choose-role page routes professional subtype to professional onboarding', async ({ page }) => {
    await page.goto('/users/choose-role', { waitUntil: 'domcontentloaded' });
    await page.waitForTimeout(1200);
    await page.getByRole('button', { name: /Photographer/i }).first().click();
    await expect(page).toHaveURL(/\/onboarding\?roleKey=PHOTOGRAPHER&schemaId=photographer_onboarding_v1&profession=photographer&intent=professional/, { timeout: 15000 });
  });

  test('dashboard route does not white-screen for guest session', async ({ page }) => {
    await page.goto('/dashboard', { waitUntil: 'domcontentloaded' });
    await expect(page.locator('body')).not.toContainText('TypeError');
    await expect(page.locator('body')).not.toContainText('Cannot read properties');
    await expect(page.locator('body').first()).toBeVisible();
  });
});
