/**
 * Navigation Test
 * Tests that all menu items navigate to the correct pages
 */

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

test.describe('Platform Navigation', () => {
  test.beforeEach(async ({ page }) => {
    // Login as platform user
    await page.goto('http://platform.lvh.me:5173/');
    await page.fill('input[name="username"]', 'poduck');
    await page.fill('input[name="password"]', 'starry12');
    await page.click('button[type="submit"]');

    // Wait for login to complete
    await page.waitForTimeout(2000);
  });

  test('should navigate to Platform Dashboard', async ({ page }) => {
    // Should be on dashboard after login
    expect(page.url()).toContain('/platform/dashboard');

    // Verify dashboard content loads
    await page.waitForTimeout(1000);
    const hasContent = await page.locator('body').count();
    expect(hasContent).toBeGreaterThan(0);
  });

  test('should navigate to all platform menu items', async ({ page }) => {
    // Navigate to Businesses
    await page.click('a[href="/platform/businesses"]');
    await page.waitForTimeout(1000);
    expect(page.url()).toContain('/platform/businesses');

    // Navigate to Users
    await page.click('a[href="/platform/users"]');
    await page.waitForTimeout(1000);
    expect(page.url()).toContain('/platform/users');

    // Navigate to Support
    await page.click('a[href="/platform/support"]');
    await page.waitForTimeout(1000);
    expect(page.url()).toContain('/platform/support');

    // Navigate back to Dashboard
    await page.click('a[href="/platform/dashboard"]');
    await page.waitForTimeout(1000);
    expect(page.url()).toContain('/platform/dashboard');
  });

  test('should reload and stay on current page', async ({ page }) => {
    // Navigate to businesses
    await page.click('a[href="/platform/businesses"]');
    await page.waitForTimeout(1000);

    const urlBeforeReload = page.url();

    // Reload page
    await page.reload();
    await page.waitForTimeout(2000);

    // Should still be on businesses page
    expect(page.url()).toBe(urlBeforeReload);

    // Should NOT see login form
    const hasLoginForm = await page.locator('input[name="username"]').count();
    expect(hasLoginForm).toBe(0);
  });
});

test.describe('Business Navigation (with test business)', () => {
  test.skip('should navigate to business pages', async ({ page }) => {
    // This test requires a business user to be set up
    // Skipping for now until test data is available
  });
});
