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

const ADMIN_EMAIL = process.env.CRANK_E2E_ADMIN_EMAIL || 'owner@crank.local';
const ADMIN_PASSWORD = process.env.CRANK_E2E_ADMIN_PASSWORD || 'change-me-admin-password';

function localized(en, ru) {
  return new RegExp(`(?:${en}|${ru})`, 'i');
}

async function login(page) {
  await page.goto('/login');
  await expect(page.locator('#login-form')).toBeVisible();
  await page.locator('#email').fill(ADMIN_EMAIL);
  await page.locator('#password').fill(ADMIN_PASSWORD);
  await page.locator('.btn-signin').click();
  await expect(page).toHaveURL(/\/$/);
  await expect(page.locator('.page-title, .page-heading').first()).toBeVisible();
}

module.exports = {
  ADMIN_EMAIL,
  ADMIN_PASSWORD,
  login,
  localized,
};
