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

test('loads the app shell, shows playback UI, and registers a service worker', async ({ page }) => {
  await page.goto('/');

  await expect(page.locator('.app-title')).toHaveText('RadioPlayer');
  await expect(page.locator('#play-btn')).toBeVisible();
  await expect(page.locator('#mute-btn')).toBeVisible();
  await expect(page.locator('#station-library')).toBeVisible();
  await expect(page.locator('#station-name')).not.toHaveText('', { timeout: 20000 });

  const serviceWorkerState = await page.evaluate(async () => {
    if (!('serviceWorker' in navigator)) {
      return { supported: false, controlled: false, scope: '' };
    }

    const registration = await navigator.serviceWorker.ready;
    return {
      supported: true,
      controlled: Boolean(navigator.serviceWorker.controller),
      scope: registration.scope,
    };
  });

  expect(serviceWorkerState.supported).toBe(true);
  expect(serviceWorkerState.controlled).toBe(true);
  expect(serviceWorkerState.scope).toContain('4174');
});
