"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");
class OperateHomePage {
    page;
    operateHeader;
    processesTab;
    informationDialog;
    editVariableButton;
    variableValueInput;
    saveVariableButton;
    editVariableSpinner;
    operateBanner;
    noPermissionsMessage;
    processPageHeading;
    applyButton;
    openButton;
    closeButton;
    messageBanner;
    constructor(page) {
        this.page = page;
        this.operateHeader = page.getByRole('link', { name: 'Camunda 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.getByRole('button', {
            name: 'Save variable',
        });
        this.editVariableSpinner = page
            .getByTestId('variable-operation-spinner')
            .locator('circle')
            .nth(1);
        this.operateBanner = page.getByRole('link', { name: 'Camunda logo Operate' });
        this.noPermissionsMessage = page
            .getByText('You don’t have access to this component')
            .first();
        this.processPageHeading = page
            .getByTestId('expanded-panel')
            .getByText('Process', { exact: true });
        this.applyButton = page.getByRole('button', { name: 'Apply' });
        this.openButton = page
            .getByTestId('variable-testVariable')
            .getByLabel('Open');
        this.closeButton = page.getByRole('button', { name: 'Got it - Dismiss' });
        this.messageBanner = page.getByRole('button', { name: 'Close' });
    }
    async clickProcessesTab() {
        await (0, clickLocatorWithRetry_1.clickLocatorWithRetry)(this.page, this.processesTab, {
            preAction: async () => {
                await this.clickMessageBanner();
            },
        });
        await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(this.page, this.processPageHeading, {
            preAction: async () => {
                await (0, test_1.expect)(this.processesTab).toBeVisible({ timeout: 10000 });
                await this.processesTab.click({ timeout: 10000 });
            },
        });
    }
    async closeInformationDialog() {
        await this.informationDialog.click();
    }
    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();
    }
    async clickMessageBanner() {
        try {
            const button = this.messageBanner.or(this.closeButton).first();
            await (0, test_1.expect)(button).toBeVisible({ timeout: 15000 });
            await button.click();
        }
        catch {
            console.log('No banner or close button found to click');
        }
    }
}
exports.OperateHomePage = OperateHomePage;
