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

export const test = base.extend({
  autoSignIn: [async ({ page }, use) => {
    const email = process.env.E2E_ADMIN_EMAIL || 'admin@px360.sa';
    const password = process.env.E2E_ADMIN_PASSWORD || 'admin123';

    await page.goto('/accounts/login/');
    await page.fill('#email', email);
    await page.fill('#password', password);
    await page.click('button[type="submit"]');

    await page.waitForURL(/\/(core\/select-hospital\/)?$/, { timeout: 10000 }).catch(() => {});
    await use(page);
  }, { auto: true }],
});

export { expect };
