"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;
    applyButton;
    openButton;
    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.getByLabel('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' });
        this.applyButton = page.getByRole('button', { name: 'Apply' });
        this.openButton = page
            .getByTestId('variable-testVariable')
            .getByLabel('Open');
    }
    async clickProcessesTab() {
        await (0, clickLocatorWithRetry_1.clickLocatorWithRetry)(this.page, this.processesTab, {
            totalTimeout: 60000,
        });
        await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(this.page, this.processPageHeading, {
            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 });
            },
            postAction: async () => {
                // Operate is a Vite SPA: a transient module/CSS preload failure
                // renders a "Something went wrong - Please reload the page" screen
                // on which the Processes tab click is a no-op. Reload to fetch fresh
                // assets so the next attempt can render the Processes view.
                await this.page.reload({ waitUntil: 'domcontentloaded' });
            },
        });
    }
    async closeInformationDialog() {
        await this.informationDialog.click();
    }
    async clickEditVariableButton(variableName) {
        const editVariableButton = 'variable-' + variableName;
        const button = this.page.getByTestId(editVariableButton).getByLabel('Edit');
        await (0, test_1.expect)(button).toBeVisible({ timeout: 30000 });
        await button.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();
    }
    async openProcess(processName) {
        await this.page.getByText(processName).click();
    }
}
exports.OperateHomePage = OperateHomePage;
