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

test.describe('PX Employee Role', () => {
  test.describe.configure({ mode: 'parallel' });

  test('login succeeds and goes to dashboard', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('px_employee');

    expect(page.url()).not.toContain('login');
    expect(page.url()).not.toContain('select-hospital');
  });

  test('cannot access config dashboard', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('px_employee');

    await page.goto('/config/');
    const blocked = page.url().includes('command-center') || page.url().includes('analytics') || page.url().toContain('login');
    expect(blocked).toBeTruthy();
  });

  test('can access complaints list', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('px_employee');

    const response = await page.goto('/complaints/');
    expect(response?.status()).toBeLessThan(400);
    expect(page.url()).not.toContain('login');
  });

  test('can access action center', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('px_employee');

    const response = await page.goto('/actions/');
    expect(response?.status()).toBeLessThan(400);
    expect(page.url()).not.toContain('login');
  });

  test('can access surveys templates', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('px_employee');

    const response = await page.goto('/surveys/templates/');
    expect(response?.status()).toBeLessThan(400);
    expect(page.url()).not.toContain('login');
  });

  test('can access surveys analytics', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('px_employee');

    const response = await page.goto('/surveys/analytics/');
    expect(response?.status()).toBeLessThan(400);
    expect(page.url()).not.toContain('login');
  });

  test('can access observations', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('px_employee');

    const response = await page.goto('/observations/');
    expect(response?.status()).toBeLessThan(400);
    expect(page.url()).not.toContain('login');
  });

  test('can access dashboard', async ({ page }) => {
    const auth = new RoleAuthHelper(page);
    await auth.login('px_employee');

    const response = await page.goto('/');
    expect(response?.status()).toBeLessThan(400);
    expect(page.url()).not.toContain('login');
  });
});
