/**
 * Sample E2E test to verify Playwright setup
 * This test validates that the E2E testing framework can connect to the server
 */

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

test.describe('Playwright Setup Validation', () => {
  test('should load the home page', async ({ page }) => {
    // Navigate to the home page
    await page.goto('/');
    
    // Wait for page to load
    await page.waitForLoadState('networkidle');
    
    // Verify the page has loaded (check for common elements)
    // Note: Adjust these selectors based on your actual HTML structure
    const title = await page.title();
    expect(title).toBeTruthy();
  });

  test('should have working navigation', async ({ page }) => {
    await page.goto('/');
    
    // Check if the page responds
    const response = await page.goto('/');
    expect(response?.status()).toBeLessThan(400);
  });

  test('should load JavaScript resources', async ({ page }) => {
    await page.goto('/');
    
    // Check if window object is available (JavaScript is running)
    const hasWindow = await page.evaluate(() => typeof window !== 'undefined');
    expect(hasWindow).toBe(true);
  });

  test('should handle basic interactions', async ({ page }) => {
    await page.goto('/');
    await page.waitForLoadState('networkidle');
    
    // Verify page is interactive
    const body = page.locator('body');
    await expect(body).toBeVisible();
  });
});

test.describe('Server Connection Tests', () => {
  test('should connect to API endpoint', async ({ request }) => {
    // Test API connectivity
    const response = await request.get('/api/health');
    
    // Either endpoint exists with 200 or returns 404 (but server is running)
    expect([200, 404]).toContain(response.status());
  });

  test('should serve static files', async ({ page }) => {
    await page.goto('/');
    
    // Check if CSS is loaded (indicates static file serving works)
    const stylesheets = await page.locator('link[rel="stylesheet"]').count();
    // We expect at least some stylesheets, or the page should load anyway
    expect(stylesheets).toBeGreaterThanOrEqual(0);
  });
});
