const { test, expect } = require('@playwright/test');

test.describe('Nexus POS — Login', () => {
  test('login page loads with form', async ({ page }) => {
    await page.goto('/pos/login');
    await expect(page).toHaveTitle(/Nexus|Login/i);
    await expect(page.locator('input[name="username"], input[name="email"], #username, #email')).toBeVisible();
    await expect(page.locator('input[type="password"], #password')).toBeVisible();
    await expect(page.locator('button[type="submit"], .btn--primary')).toBeVisible();
  });

  test('invalid credentials show error', async ({ page }) => {
    await page.goto('/pos/login');
    const userInput = page.locator('input[name="username"], input[name="email"], #username, #email').first();
    const passInput = page.locator('input[type="password"], #password').first();
    const submitBtn = page.locator('button[type="submit"], .btn--primary').first();

    await userInput.fill('invalid_user');
    await passInput.fill('wrong_password');
    await submitBtn.click();

    // Expect error toast or message
    await expect(page.locator('.toast, .alert, .error, [role="alert"]')).toBeVisible({ timeout: 5000 });
  });
});
