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

test.describe('Marketing frontend smoke', () => {
  test('landing renders without console errors and CTA leads to packages', async ({ page }) => {
    const consoleErrors: string[] = [];
    page.on('console', (msg) => {
      if (msg.type() === 'error') {
        consoleErrors.push(msg.text());
      }
    });

    const response = await page.goto('/');
    expect(response?.ok()).toBeTruthy();

    const acceptCookies = page.getByRole('button', { name: /akzeptieren|accept/i });
    if (await acceptCookies.isVisible()) {
      await acceptCookies.click();
    }

    await expect(page.getByRole('heading', { level: 1, name: /Dein Event|Fotospiel/i })).toBeVisible();
    const heroCta = page.locator('#hero').getByRole('link', {
      name: /Pakete ansehen|Pakete entdecken|Discover Packages/i,
    });
    await expect(heroCta).toBeVisible();

    await heroCta.click();
    await expect(page).toHaveURL(/\/packages/);

    await expect(page.getByRole('heading', { level: 1 })).toBeVisible();

    expect(consoleErrors).toEqual([]);
  });

  test('packages page lists packages and register CTAs', async ({ page }) => {
    const response = await page.goto('/packages');
    expect(response?.ok()).toBeTruthy();

    const acceptCookies = page.getByRole('button', { name: /akzeptieren|accept/i });
    if (await acceptCookies.isVisible()) {
      await acceptCookies.click();
    }

    const packageCards = page.locator('section >> text=/Starter|Standard|Premium/');
    await expect(packageCards.first()).toBeVisible();
  });
});
