"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OperateProcessInstancePage = void 0;
const test_1 = require("@playwright/test");
const sleep_1 = require("../../utils/sleep");
class OperateProcessInstancePage {
    page;
    diagram;
    completedIcon;
    diagramSpinner;
    activeIcon;
    variablesList;
    messageVariable;
    statusVariable;
    constructor(page) {
        this.page = page;
        this.diagram = page.getByTestId('diagram');
        this.completedIcon = page
            .getByTestId('instance-header')
            .getByTestId('COMPLETED-icon');
        this.diagramSpinner = page.getByTestId('diagram-spinner');
        this.activeIcon = page
            .getByTestId('instance-header')
            .getByTestId('ACTIVE-icon');
        this.variablesList = page.getByTestId('variables-list');
        this.messageVariable = page.getByTestId('variable-message');
        this.statusVariable = page.getByTestId('variable-status');
    }
    async connectorResultVariableName(name) {
        return await this.page.getByTestId(name);
    }
    async connectorResultVariableValue(variableName) {
        return await this.page.getByTestId(variableName).locator('td').last();
    }
    async completedIconAssertion(onRetry) {
        let retryCount = 0;
        const maxRetries = 5;
        while (retryCount < maxRetries) {
            try {
                await (0, test_1.expect)(this.completedIcon).toBeVisible({
                    timeout: 90000,
                });
                return; // Exit the function if the expectation is met
            }
            catch (error) {
                // If the completed icon isn't found, reload the page and try again
                retryCount++;
                console.log(`Attempt ${retryCount} failed. Retrying...`);
                if (onRetry) {
                    await onRetry();
                }
                await this.page.reload();
                await (0, sleep_1.sleep)(10000);
            }
        }
        throw new Error(`Completed icon not visible after ${maxRetries} attempts.`);
    }
    async activeIconAssertion() {
        let retryCount = 0;
        const maxRetries = 3;
        while (retryCount < maxRetries) {
            try {
                await (0, test_1.expect)(this.activeIcon).toBeVisible({
                    timeout: 90000,
                });
                return; // Exit the function if the expectation is met
            }
            catch (error) {
                // If the active icon isn't found, reload the page and try again
                retryCount++;
                console.log(`Attempt ${retryCount} failed. Retrying...`);
                await this.page.reload();
                await (0, sleep_1.sleep)(10000);
            }
        }
        throw new Error(`Active icon not visible after ${maxRetries} attempts.`);
    }
}
exports.OperateProcessInstancePage = OperateProcessInstancePage;
