"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlayPage = void 0;
const test_1 = require("@playwright/test");
const maxWaitTimeSeconds = 120000;
class PlayPage {
    page;
    completeJobButton;
    constructor(page) {
        this.page = page;
        this.completeJobButton = page
            .getByTestId('diagram')
            .getByLabel('Complete job');
    }
    async waitForCompleteJobButtonToBeAvailable() {
        await (0, test_1.expect)(this.completeJobButton).toBeVisible({
            timeout: maxWaitTimeSeconds,
        });
    }
    async clickCompleteJobButton() {
        await this.completeJobButton.click();
    }
    async clickStartInstanceButton() {
        await this.page
            .getByTestId('diagram')
            .getByLabel('Start instance', { exact: true })
            .click();
    }
    async dismissStartModal() {
        await this.page
            .getByRole('button', {
            name: 'Start a process instance',
        })
            .click();
    }
    async waitForInstanceDetailsToBeLoaded() {
        const maxRetries = 2;
        let attempts = 0;
        while (attempts < maxRetries) {
            try {
                await (0, test_1.expect)(this.page.getByText(/process instance key/i)).toBeVisible({
                    timeout: maxWaitTimeSeconds,
                });
                await (0, test_1.expect)(this.page.getByText(/This process instance has no variables/i)).toBeVisible({
                    timeout: maxWaitTimeSeconds,
                });
                return;
            }
            catch (error) {
                if (attempts >= maxRetries - 1)
                    throw error;
                await this.page.reload();
                attempts++;
            }
        }
    }
    async waitForNextElementToBeActive(historyItem) {
        await (0, test_1.expect)(this.page.getByText(new RegExp(`^${historyItem}`, 'i'))).toBeVisible({
            timeout: maxWaitTimeSeconds,
        });
    }
    async waitForProcessToBeCompleted() {
        await (0, test_1.expect)(this.page.getByText('Completed')).toBeVisible({
            timeout: maxWaitTimeSeconds,
        });
    }
}
exports.PlayPage = PlayPage;
