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

test.use({
  locale: 'en-US'
});

async function waitForBlazorConnection(page: Page) {
  await page.waitForTimeout(750);
}

test('date picker popup is monday-first and uses european formatting', async ({ page }) => {
  await page.setViewportSize({ width: 1440, height: 960 });
  await page.goto('/calendar-event', { waitUntil: 'networkidle' });
  await waitForBlazorConnection(page);

  const startDateInput = page.getByTestId('calendar-event-start-date-input');
  await expect(startDateInput).toBeVisible();

  await startDateInput.click();

  const popup = page.getByTestId('calendar-event-start-date-popover');
  await expect(popup).toBeVisible();

  const weekdayHeaders = popup.getByTestId('date-picker-weekday');
  await expect(weekdayHeaders).toHaveCount(7);

  await expect(weekdayHeaders.first()).toHaveText(/^(Mon|Lun)$/);
  await page.getByTestId('calendar-event-start-date-day-2026-04-22').click();
  await expect(startDateInput).toHaveValue(/^22\/\d{2}\/\d{4}$/);
});