// @ts-check
// Verifies the language picker + German translation of the UI chrome.
const { test, expect } = require('@playwright/test');

test('defaults to English and shows the language picker', async ({ page }) => {
  await page.goto('/', { waitUntil: 'domcontentloaded' });
  await expect(page.locator('#app-lang-picker')).toBeVisible();
  await expect(page.locator('.nav-item', { hasText: 'Clone a Voice' }).first()).toBeVisible();
});

test('German translates the navigation and section titles', async ({ page }) => {
  await page.addInitScript(() => { try { localStorage.setItem('app-lang', 'de'); } catch (e) {} });
  await page.goto('/', { waitUntil: 'domcontentloaded' });
  await page.waitForFunction(() => typeof window.applyI18n === 'function', null, { timeout: 15_000 });
  await page.waitForTimeout(1500);
  await expect(page.locator('#app-lang-picker')).toHaveValue('de');
  await expect(page.locator('.nav-item', { hasText: 'Stimme klonen' }).first()).toBeVisible();
  await expect(page.getByText('Meine Stimmen').first()).toBeVisible();
  // English source text should no longer be present in the nav
  await expect(page.locator('.nav-item', { hasText: 'Get Voices Online' })).toHaveCount(0);
});
