"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OperateHomePage = void 0;
const test_1 = require("@playwright/test");
class OperateHomePage {
    page;
    operateBanner;
    processesTab;
    informationDialog;
    editVariableButton;
    variableValueInput;
    saveVariableButton;
    editVariableSpinner;
    applyButton;
    openButton;
    constructor(page) {
        this.page = page;
        this.operateBanner = page.getByRole('link', { name: 'Camunda logo Operate' });
        this.processesTab = page.getByRole('link', { name: 'Processes' });
        this.informationDialog = page.getByRole('button', {
            name: 'Close this dialog',
        });
        this.editVariableButton = page.getByTestId('edit-variable-button');
        this.variableValueInput = page.getByTestId('edit-variable-value');
        this.saveVariableButton = page.getByLabel('Save variable');
        this.editVariableSpinner = page
            .getByTestId('variable-operation-spinner')
            .locator('circle')
            .nth(1);
        this.applyButton = page.getByRole('button', { name: 'Apply' });
        this.openButton = page
            .getByTestId('variable-testVariable')
            .getByLabel('Open');
    }
    async operateBannerIsVisible() {
        await (0, test_1.expect)(this.operateBanner).toBeVisible({ timeout: 30000 });
    }
    async clickProcessesTab() {
        const maxRetries = 3;
        for (let retries = 0; retries < maxRetries; retries++) {
            try {
                await (0, test_1.expect)(this.processesTab).toBeVisible({ timeout: 30000 });
                await this.processesTab.click({ timeout: 30000 });
                await (0, test_1.expect)(this.page.locator('label').filter({ hasText: 'Completed' }).first()).toBeVisible();
                return;
            }
            catch (error) {
                console.warn(`Click attempt ${retries + 1} failed: ${error}`);
            }
        }
        throw new Error(`Failed to click the processes tab after ${maxRetries} attempts.`);
    }
    async clickEditVariableButton(variableName) {
        const editVariableButton = 'variable-' + variableName;
        await this.page.getByTestId(editVariableButton).getByLabel('Edit').click();
    }
    async clickVariableValueInput() {
        await this.variableValueInput.click();
    }
    async clearVariableValueInput() {
        await this.variableValueInput.clear();
    }
    async fillVariableValueInput(newValue) {
        await this.openButton.click();
        await this.page
            .getByLabel('Edit Variable "testVariable"')
            .getByText('"testValue"')
            .dblclick();
        await this.page.keyboard.press('Backspace');
        await this.page.keyboard.type(newValue);
    }
    async clickSaveVariableButton() {
        await this.applyButton.click();
        try {
            await this.saveVariableButton.click();
        }
        catch {
            // additional save not required -> continue
        }
    }
}
exports.OperateHomePage = OperateHomePage;
