"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OperateHomePage = void 0;
const test_1 = require("@playwright/test");
const clickLocatorWithRetry_1 = require("../../utils/assertionHelpers/clickLocatorWithRetry");
const expectLocatorWithRetry_1 = require("../../utils/assertionHelpers/expectLocatorWithRetry");
const constants_1 = require("../../utils/constants");
class OperateHomePage {
    page;
    operateBanner;
    processesTab;
    informationDialog;
    editVariableButton;
    variableValueInput;
    saveVariableButton;
    editVariableSpinner;
    licenseKeyTagNonProduction;
    licenseKeyTagProduction;
    processPageHeading;
    constructor(page) {
        this.page = page;
        this.operateBanner = page.getByRole('link', { name: 'Camunda logo Operate' });
        this.processesTab = page.getByRole('link', {
            name: 'Processes',
            exact: true,
        });
        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.locator('[aria-label="Save variable"]');
        this.editVariableSpinner = page
            .getByTestId('variable-operation-spinner')
            .locator('circle')
            .nth(1);
        this.licenseKeyTagNonProduction = page
            .getByText('Non-production license')
            .first();
        this.licenseKeyTagProduction = page.getByText('Production license').first();
        this.processPageHeading = page
            .getByTestId('expanded-panel')
            .getByRole('heading', { name: 'Process' });
    }
    async clickProcessesTab() {
        await (0, clickLocatorWithRetry_1.clickLocatorWithRetry)(this.page, this.processesTab, {
            totalTimeout: 60000,
        });
        await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(this.page, this.processPageHeading, {
            maxRetries: 5,
            visibilityTimeout: 15000,
            totalTimeout: 90000,
            preAction: async () => {
                await (0, test_1.expect)(this.processesTab).toBeVisible({
                    timeout: constants_1._1_SECOND_IN_MS * 4,
                });
                await this.processesTab.click({ timeout: constants_1._1_SECOND_IN_MS * 4 });
            },
        });
    }
    async closeInformationDialog() {
        await this.informationDialog.click();
    }
    async clickEditVariableButton(variableName) {
        // Edit button is only visible on row hover
        const varRow = this.page.getByTestId('variable-' + variableName);
        await varRow.hover();
        const button = this.page.locator(`[aria-label="Edit variable ${variableName}"]`);
        await (0, test_1.expect)(button).toBeVisible({ timeout: 10000 });
        await button.click({ force: true });
    }
    async clickVariableValueInput() {
        const monacoLine = this.variableValueInput.locator('.view-line').first();
        if (await monacoLine.isVisible({ timeout: 3000 }).catch(() => false)) {
            await monacoLine.click();
        }
        else {
            await this.variableValueInput.click();
        }
    }
    async clearVariableValueInput() {
        const monacoLine = this.variableValueInput.locator('.view-line').first();
        if (await monacoLine.isVisible({ timeout: 3000 }).catch(() => false)) {
            await monacoLine.click();
            await this.page.keyboard.press('Control+A');
            await this.page.keyboard.press('Delete');
        }
        else {
            await this.variableValueInput.clear();
        }
    }
    async fillVariableValueInput(value) {
        const monacoLine = this.variableValueInput.locator('.view-line').first();
        if (await monacoLine.isVisible({ timeout: 3000 }).catch(() => false)) {
            await monacoLine.click();
            await this.page.keyboard.insertText(value);
        }
        else {
            await this.variableValueInput.fill(value);
        }
    }
    async clickSaveVariableButton() {
        await this.saveVariableButton.click({ force: true });
    }
    async openProcess(processName) {
        await this.page.getByText(processName).click();
    }
}
exports.OperateHomePage = OperateHomePage;
