"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskProcessesPage = void 0;
const test_1 = require("@playwright/test");
const clickLocatorWithRetry_1 = require("../../utils/assertionHelpers/clickLocatorWithRetry");
const expectTextWithPagination_1 = require("../../utils/assertionHelpers/expectTextWithPagination");
class TaskProcessesPage {
    page;
    popupContinueButton;
    popup;
    processes;
    availableTasks;
    waitingForTasksText;
    constructor(page) {
        this.page = page;
        this.popupContinueButton = page.getByRole('button', { name: 'Continue' });
        this.popup = page.getByLabel('Start your process on demand');
        this.processes = page.locator('[data-testid="process-tile"]');
        this.availableTasks = page.getByTitle('Available tasks').first();
        this.waitingForTasksText = this.page.getByText('Waiting for tasks...');
    }
    async clickpopupContinueButton() {
        await this.page.waitForTimeout(3000);
        if ((await this.popupContinueButton.count()) > 0) {
            await (0, clickLocatorWithRetry_1.clickLocatorWithRetry)(this.page, this.popupContinueButton);
        }
        await (0, test_1.expect)(this.popup.first()).not.toBeVisible({ timeout: 10000 });
    }
    async startProcess(name) {
        if (process.env.TASKLIST_VERSION === 'v2') {
            await (0, expectTextWithPagination_1.expectTextWithPagination)(this.page, name);
            const container = this.page
                .locator('div')
                .filter({
                hasText: new RegExp(`^${name}.*Start process$`),
            })
                .nth(1);
            await container
                .getByRole('button', { name: 'Start process', exact: true })
                .first()
                .click({ timeout: 60000 });
            await (0, test_1.expect)(this.waitingForTasksText).not.toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(this.availableTasks.first()).toBeVisible({
                timeout: 90000, //redirection to tasks tab
            });
        }
        else if (process.env.TASKLIST_VERSION === 'v1') {
            const processStartButton = this.processes
                .filter({ hasText: name })
                .nth(0)
                .getByRole('button', { name: 'Start process' });
            await (0, test_1.expect)(processStartButton).toBeVisible({ timeout: 30000 });
            await processStartButton.click();
            await (0, test_1.expect)(this.waitingForTasksText).not.toBeVisible({
                timeout: 60000,
            });
            await (0, test_1.expect)(this.availableTasks.first()).toBeVisible({
                timeout: 90000,
            });
        }
        else {
            throw new Error(`Unknown TASKLIST_VERSION: ${process.env.TASKLIST_VERSION}`);
        }
    }
}
exports.TaskProcessesPage = TaskProcessesPage;
