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

test.describe('MC Cars - Customer Changes Verification', () => {

  test.beforeEach(async ({ page }) => {
    await page.goto('/');
    await page.waitForLoadState('domcontentloaded');
    await page.waitForTimeout(1000);
  });

  test('Page loads successfully', async ({ page }) => {
    await expect(page).toHaveTitle(/MC Cars/);
  });

  test('Hero section - Flotte ansehen button removed', async ({ page }) => {
    await expect(page.getByText('Flotte ansehen')).not.toBeVisible();
    await expect(page.getByText('View fleet')).not.toBeVisible();
  });

  test('Hero section - 24/7 Support stat removed', async ({ page }) => {
    await expect(page.getByText('24/7')).not.toBeVisible();
  });

  test('Hero section - Faire Kaution stat still visible', async ({ page }) => {
    const kautionStat = page.getByText('Faire Kaution', { exact: true });
    await expect(kautionStat).toBeVisible();
  });

  test('Hero section - Fahrzeuge stat still visible', async ({ page }) => {
    const vehiclesSection = page.locator('.hero-stats');
    await expect(vehiclesSection).toBeVisible();
  });

  test('Fleet section - Unsere Flotte eyebrow removed', async ({ page }) => {
    await expect(page.getByText('Unsere Flotte')).not.toBeVisible();
    await expect(page.getByText('Our Fleet')).not.toBeVisible();
  });

  test('Fleet section - Title still visible', async ({ page }) => {
    await expect(page.getByText('Handverlesen. Gepflegt. Startklar.')).toBeVisible();
  });

  test('Navigation - Warum wir link removed', async ({ page }) => {
    await expect(page.getByText('Warum wir')).not.toBeVisible();
    await expect(page.getByText('Why us')).not.toBeVisible();
  });

  test('Navigation - Other links still present', async ({ page }) => {
    const nav = page.getByLabel('Hauptnavigation');
    await expect(nav.getByRole('link', { name: 'Fahrzeuge' }).first()).toBeVisible();
    await expect(nav.getByRole('link', { name: 'Stimmen' })).toBeVisible();
    await expect(nav.getByRole('link', { name: 'Buchen' }).first()).toBeVisible();
    await expect(nav.getByRole('link', { name: 'Jetzt buchen' })).toBeVisible();
  });

  test('Reviews - Ferrari references in reviews', async ({ page }) => {
    await page.locator('#stimmen').scrollIntoViewIfNeeded();
    const reviewsSection = page.locator('#stimmen');
    await expect(reviewsSection).toBeVisible();
  });

  test('Reviews - GT3 references removed', async ({ page }) => {
    await expect(page.getByText('GT3')).not.toBeVisible();
  });

  test('Footer - correct content', async ({ page }) => {
    await expect(page.getByText('Rechtliches')).toBeVisible();
    await expect(page.getByText('Impressum')).toBeVisible();
    await expect(page.getByText('Datenschutz')).toBeVisible();
    await expect(page.getByText('hello@mc-cars.at')).toBeVisible();
  });

  test('Footer - Steiermark reference updated', async ({ page }) => {
    await expect(page.getByText('Made in Steiermark')).toBeVisible();
  });

 test('Language toggle works', async ({ page }) => {
    const langToggle = page.locator('.lang-toggle');
    await expect(langToggle).toBeVisible();

    // Switch to English
    await langToggle.click();
    await page.waitForTimeout(500);
    await expect(langToggle).toHaveText('DE');
    await expect(page.getByText('Drive at the highest level.')).toBeVisible();

    // Switch back to German
    await langToggle.click();
    await page.waitForTimeout(500);
    await expect(langToggle).toHaveText('EN');
    await expect(page.getByRole('heading', { name: /Niveau/ })).toBeVisible();
  });

  test('Fleet section - vehicle cards visible', async ({ page }) => {
    await page.locator('#fahrzeuge').scrollIntoViewIfNeeded();
    const vehicleCards = page.locator('.vehicle-card');
    await expect(vehicleCards.first()).toBeVisible();
  });

  test('Booking section visible', async ({ page }) => {
    await page.locator('#buchen').scrollIntoViewIfNeeded();
    await expect(page.getByRole('heading', { name: 'Jetzt buchen' })).toBeVisible();
  });

  test('SEO title updated', async ({ page }) => {
    const title = await page.title();
    expect(title).toContain('Ferrari');
  });
});
